Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

第 3 章 Podman

目录

3.1. 安装 Podman
3.1.1. RockyLinux 安装 Podman
3.1.2. Almalinux 9.0
3.1.3. MacOS 安装 Podman
3.1.4. 初始化 Podman
3.1.5. 让 Podman 支持 Docker Compose
3.1.6. 配置 Podman
3.1.7.
3.2. podman 管理
3.2.1. 虚拟机管理
3.2.2. 镜像管理
3.2.3. Registry
3.3. 按例
3.3.1. podman run 用法
3.3.2. mysql
3.3.3. 制作镜像

3.1. 安装 Podman

3.1.1. RockyLinux 安装 Podman

某些 Redhat 家族的 Linux 是自带 Podman,例如 Almalinux 9.0,RockyLinux没有自带 podman 需要自己安装,是方法执行下面的命令

			
[root@netkiller ~]# dnf install -y podman
		
		

3.1.2. Almalinux 9.0

Almalinux 9.0 自带 podman

		 
systemctl enable podman		
		
		

3.1.3. MacOS 安装 Podman

MacOS 安装方法

			 
brew install podman
            
		

3.1.4. 初始化 Podman

初始化,启动 Podman

			 
podman machine init
podman machine start
            
		

操作演示

			 
neo@MacBook-Pro-M2 ~ % podman machine init
Downloading VM image: fedora-coreos-37.20221127.2.0-qemu.aarch64.qcow2.xz: done  
Extracting compressed file Image resized.
Machine init complete
To start your machine run:

    podman machine start

neo@MacBook-Pro-M2 ~ % podman machine start          
Starting machine "podman-machine-default"
Waiting for VM ...
Mounting volume... /Users/neo:/Users/neo

This machine is currently configured in rootless mode. If your containers
require root permissions (e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command: 

    podman machine set --rootful

API forwarding listening on: /Users/neo/.local/share/containers/podman/machine/podman-machine-default/podman.sock

The system helper service is not installed; the default Docker API socket
address can't be used by podman. If you would like to install it run the
following commands:

    sudo /opt/homebrew/Cellar/podman/4.3.1/bin/podman-mac-helper install
    podman machine stop; podman machine start

You can still connect Docker API clients by setting DOCKER_HOST using the
following command in your terminal session:

    export DOCKER_HOST='unix:///Users/neo/.local/share/containers/podman/machine/podman-machine-default/podman.sock'

Machine "podman-machine-default" started successfully
            
		

3.1.5. 让 Podman 支持 Docker Compose

启用 socket

		 
systemctl enable podman.socket
systemctl start podman.socket
systemctl status podman.socket
		
		

验证 sock 是否正常工作

		 
[root@localhost ~]# curl -H "Content-Type: application/json" --unix-socket /run/podman/podman.sock http://localhost/_ping
OK
		
		

此时可以使用 docker compose

		 
[root@localhost ~]# ln -s /run/podman/podman.sock /var/run/docker.sock		
		
		

3.1.6. 配置 Podman

/etc/containers/registries.conf

3.1.7. 

		 
$ podman pull maven
$ podman run -v ~/.m2:/root/.m2 \
-v /root/bottleneck:/root/bottleneck \
-w /root/bottleneck \
maven:latest \
mvn package