无根用户管理podman
目录
在允许没有root特权的用户运行Podman之前,管理员必须安装或构建Podman并完成以下配置
基础设置
cgroup V2Linux内核功能允许用户限制普通用户容器可以使用的资源,如果使用cgroupV2启用了运行Podman的Linux发行版,则可能需要更改默认的OCI运行时。某些较旧的版本runc不适用于cgroupV2,必须切换到备用OCI运行时crun。
[root@localhost ~]# dnf -y install crun //centos8自带,可以直接进行安装
[root@localhost ~]# vim /usr/share/containers/containers.conf
runtime = "crun" //取消注释
#runtime = "runc" //注释掉
//启动一个容器
[root@localhost ~]# podman run -d --name web nginx
Resolving "nginx" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/library/nginx:latest...
Getting image source signatures
Copying blob b4df32aa5a72 done
Copying blob 589b7251471a done
Copying blob a0bcbecc962e done
Copying blob 186b1aaa4aa6 done
Copying blob a2abf6c4d29d done
Copying blob a9edb18cadd1 done
Copying config 605c77e624 done
Writing manifest to image destination
Storing signatures
230ef7f477fe7b5348bbef97ac6c28d3a38b2a535f5398b06b735530922d9634
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
230ef7f477fe docker.io/library/nginx:latest nginx -g daemon o... 13 seconds ago Up 13 seconds ago web
[root@localhost ~]# podman inspect web | grep -i ociruntime
"OCIRuntime": "crun",
安装slirp4netns和fuse-overlayfs
在普通用户环境中使用Podman时,建议使用fuse-overlayfs而不是VFS文件系统,至少需要版本0.7.6。现在新版本默认就是了
[root@localhost ~]# dnf -y install slirp4netns fuse-overlayfs
[root@localhost ~]# vim /etc/containers/storage.conf
mount_program = "/usr/bin/fuse-overlayfs" //取消注释
subuid和 subgid配置
Podman要求运行它的用户在/ etc / subuid和/ etc / subgid文件中列出一系列UID,shadow-utils或newuid包提供这些文件
[root@localhost ~]# yum -y install shadow-utils
//可以在/etc/ subuid和/etc/ subgid查看,每个用户的值必须唯一且没有任何重叠。
[[root@localhost ~]# useradd zz
[root@localhost ~]# cat /etc/subuid
zz:100000:65536
[root@localhost ~]# cat /etc/subgid
zz:100000:65536
[root@localhost ~]#
//可以在/etc/subuid和/etc/subgid查看,每个用户的值必须唯一且没有任何重叠。
[root@localhost ~]# vim /etc/sysctl.conf
net.ipve4.ping_group_range=0 200000 //添加此行,大于100000这个就表示tom可以操作podman
这个文件的格式是 USERNAME:UID:RANGE中/etc/passwd或输出中列出的用户名getpwent。
- 为用户分配的初始 UID。
- 为用户分配的 UID 范围的大小。
该usermod程序可用于为用户分配 UID 和 GID,而不是直接更新文件。
[root@localhost ~]# useradd xx
[root@localhost ~]# cat /etc/subuid /etc/subgid
zz:100000:65536
xx:165536:65536
zz:100000:65536
xx:165536:65536
[root@localhost ~]# usermod --add-subuids 200000-201000 --add-subgids 200000-201000 xx
[root@localhost ~]# cat /etc/subuid /etc/subgid
zz:100000:65536
xx:165536:65536
zz:100000:65536
xx:165536:65536
[root@localhost ~]# usermod --del-subuids 165536-231072 --del-subgids 165536-231072 xx //--del 删除
[root@localhost ~]# cat /etc/subuid /etc/subgid
zz:100000:65536
zz:100000:65536
[root@localhost ~]# usermod --add-subuids 200000-201000 --add-subgids 200000-201000 xx //--add 添加
[root@localhost ~]# cat /etc/subuid /etc/subgid
zz:100000:65536
xx:200000:1001
zz:100000:65536
xx:200000:1001
用户配置文件
三个主要的配置文件是container.conf、storage.conf和registries.conf。用户可以根据需要修改这些文件。
container.conf(容器配置文件)
//查看用户配置文件方法
[root@localhost ~]# cat /usr/share/containers/containers.conf //常用
//方法
[root@localhost ~]# ca