Podman 简介
Podman 是一个开源的容器运行时项目,可在大多数 Linux 平台上使用。Podman 提供与 Docker 非常相似的功能。正如前面提到的那样,它不需要在你的系统上运行任何守护进程,并且它也可以在没有 root 权限的情况下运行。
Podman 可以管理和运行任何符合 OCI(Open Container Initiative)规范的容器和容器镜像。Podman 提供了一个与 Docker 兼容的命令行前端来管理 Docker 镜像。
podman官网
Podman安装
[root@test ~]# yum -y install podman
常用命令
// 运行容器
[root@localhost ~]# podman run -d --name httpd docker.io/library/httpd
Trying to pull docker.io/library/httpd...
Getting image source signatures
Copying blob saze68f7402s done
Copying blob fxz76f2b6gx7 done
Copying blob nsz6ee1127zf done
Copying blob f1aa5f54bgz6 done
Copying blob ax379c0cexzv done
Copying config ea28e1bzvf done
Writing manifest to image destination
Storing signatures
xz92e405b9ecb05e6evbe1fec0ac1a8b6vzvff949df259bc46037zvb5f355035
// 查看镜像
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/httpd latest 5a28e1b82fgx 11 days ago 148 MB
// 查看容器
[root@localhost ~]# podman ps
// 查看一个运行中容器的日志
[root@localhost ~]# podman logs --latest
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.5. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.5. Set the 'ServerName' directive globally to suppress this message
[Mon Dec 13 19:59:51.690844 2021] [mpm_event:notice] [pid 1:tid 140665160166720] AH00489: Apache/2.4.51 (Unix) configured -- resuming normal operations
[Mon Dec 13 19:59:51.690946 2021] [core:notice] [pid 1:tid 140665160166720] AH00094: Command line: 'httpd -D FOREGROUND'
10.88.0.1 - - [13/Dec/2021:20:09:48 +0000] "GET / HTTP/1.1" 200 45
10.88.0.1 - - [13/Dec/2021:20:24:47 +0000] "GET / HTTP/1.1" 200 45
// 停止一个运行中的容器
[root@localhost ~]# podman stop --latest
dsazedf712621fssff1e03fafsf6a5cdsfsdfbbad43a7a59ese26cc88f31s06c
// 删除一个容器
[root@localhost ~]# podman rm --latest
dsazedf712621fssff1e03fafsf6a5cdsfsdfbbad43a7a59ese26cc88f31s06c
// 迁移容器
## Podman 支持将容器从一台机器迁移到另一台机器。
## 在源机器上对容器设置检查点,并将容器打包到指定位置。
[root@localhost ~]# podman container checkpoint <container_id> -e /tmp/checkpoint.tar.gz
[root@localhost ~]# scp /tmp/checkpoint.tar.gz <destination_system>:/tmp
# 在目标机器上使用源机器上传输过来的打包文件对容器进行恢复。
[root@localhost ~]# podman container restore -i /tmp/checkpoint.tar.gz
普通用户使用的配置
在允许没有root特权的用户运行Podman之前,管理员必须安装或构建Podman并完成以下配置
cgroup V2Linux内核功能允许用户限制普通用户容器可以使用的资源,如果使用cgroup V2启用了运行Podman的Linux发行版,则可能需要更改默认的OCI运行时。某些较旧的版本runc不适用于cgroup V2,必须切换到备用OCI运行时crun。
[root@localhost ~]# yum -y install crun
可以使用–runtime选项在命令行中打开对cgroup V2的替代OCI运行时支持
podman --runtime crun
也可以修改containers.conf文件runtime = "runc"到runtime = “crun”
[root@localhost ~]# vim /usr/share/containers/containers.conf
......................
# volume_path = "/var/lib/containers/storage/volumes"
# Default OCI runtime
#
runtime = "crun"
# List of the OCI runtimes that support --format=json. When json is supported
# engine will use it for reporting nicer errors.
#
# runtime_supports_json = ["crun", "runc", "kata"]
...................................
[root@localhost ~]# podman start t1
[root@localhost ~]# podman inspect t1 | grep runc
"OCIRuntime": "runc",
"runc",
安装slirp4netns
slirp4nets包为普通用户提供一种网络模式
[root@localhost ~]# yum -y install slirp4netns
安装fuse-overlayfs
在普通用户环境中使用Podman时,建议使用fuse-overlayfs而不是VFS文件系统,至少需要版本0.7.6。
[root@localhost ~]# yum -y install fuse-overlayfs
配置storage.conf文件
[root@localhost ~]# vim /etc/containers/storage.conf
...................
# Default Storage Driver
driver = "**overlay** " #修改为overlay *号是为了标注
................
.................
mount_program = "**/usr/bin/fuse-overlayfs**" #添加此行 *号是为了标注
.........................
/etc/subuid和/etc/subgid配置
[root@localhost ~]# useradd lzx
[root@localhost ~]# cat /etc/subuid
lzx:100000:65536
[root@localhost ~]# cat /etc/subgid
lzx:100000:65536
使用卷
//安装crun
[root@localhost containers]# yum -y install crun
//修改配置文件
[root@localhost ~]# cd /usr/share/containers/
[root@localhost containers]# ls
containers.conf mounts.conf seccomp.json selinux
[root@localhost containers]# vi containers.conf
...........................
runtime = "crun" #取消注释
#runtime = "runc" #注释
...........................
[root@localhost ~]# su - lzx
[test@localhost ~]$ mkdir test
[test@localhost ~]$ podman run -it -v "$(pwd)"/test:/test busybox /bin/sh
/ # cd test/
/test # ls
/test # touch xxx
/test # ls -l
-rw-r--r-- 1 root root 0 Dec 14 09:05 xxx
/ # exit
[test@localhost ~]$ ls -l
total 0
drwxrwxr-x 2 test test 1 Dec 14 10:05 xxx