Podman,作为docker的(升级/魔改/进阶/优化)版本,现已登陆openSUSE Leap 15.1!,不要docker-io! 不要systemctl start docker ! 下载即装即用!还再犹豫什么,赶快卸载Docker安装podman吧



2021.3.06更新:若按照本文后,在pull镜像结束阶段出现 potentially insufficient UIDs or GIDs available in user namespace (requested 0:42 for /etc/shadow) 错误,请尝试运行 podman system migrate 命令



吃完安利 简单一说后,先描述一下我碰到的问题,首先,在执行podman命令时,给出了这样一个WARNING

WARN[0000] cannot find mappings for user 马赛克: No subuid ranges found for user "马赛克" in /etc/subuid 
WARN[0000] using rootless single mapping into the namespace. This might break some images. Check /etc/subuid and /etc/subgid for adding subids

鉴于作为码农预备役中一员的敏感性,WARNING什么的不管他就是了,又不是跑不了,命令跑的这么稳定,我的环境怎么会有问题,但是事实却是……

Trying to pull docker.io/library/debian:latest...Getting image source signatures
Copying blob 6f2f362378c5 done
Copying config e1de74e67c done
Writing manifest to image destination
Storing signatures
Error: error creating container storage: error creating read-write layer with ID "d21e1aa53311dee39e57aeaf3ad545529989f71edbf1ec2989d5edf3675675be": there might not be enough IDs available in the namespace (requested 0:65534 for /home/马赛克/.local/share/containers/storage/vfs/dir/d21e1aa53311dee39e57aeaf3ad545529989f71edbf1ec2989d5edf3675675be/etc/gshadow): lchown /home/马赛克/.local/share/containers/storage/vfs/dir/d21e1aa53311dee39e57aeaf3ad545529989f71edbf1ec2989d5edf3675675be/etc/gshadow: invalid argument

嗯?容器起不来?这可就是真的见鬼了,赶快切到docker下试试

╰─➤  docker run -it debian:latest
Unable to find image 'debian:latest' locally
latest: Pulling from library/debian
6f2f362378c5: Pull complete 
Digest: sha256:118cf8f3557e1ea766c02f36f05f6ac3e63628427ea8965fb861be904ec35a6f
Status: Downloaded newer image for debian:latest
root@01ca97b541ba:/# 

这不是很正常吗???
再去root下测试一下

╰─# podman run -it debian:latest
root@bac474be0001:/# 

非常正常,但是每次都要切到root很麻烦,懒啊

于是乎,在疑惑与懒惰的驱动下,我先是点开了 www.baidu.com
没 有 答 案(正常)
然后我又去了 www.google.com
仅有的两个github issue就像救命稻草一样出现了!
但是仍然有问题,issue中所提到的先是基于ubuntu的环境,最终解决办法是安装uidmap这个包,这个包在openSUSE下自然是搜不到的; 另一个是在openSUSE下的问题,但是只是说利用“shadowutil”修复了,并未描述修复流程。哦豁,傻了

没办法只能返回来继续看报错,看来看去,突然发现了其中一句报错

there might not be enough IDs available in the namespace

再结合最开始的WARNING

WARN[0000] cannot find mappings for user 马赛克: No subuid ranges found for user "马赛克" in /etc/subuid 

很明显,问题就是应该出在了/etc/subuid与/etc/subgid这两个文件中了
那这两个文件又是什么呢,这又牵扯到了docker中关于namespace的相关了,在此对namespace仅做一简要说明

Linux 内核实现 namespace 的主要目的就是为了实现轻量级虚拟化(容器) 服务,构建一个相对隔离的 shell 环境。在同一个 namespace 下的进程可以感知 彼此的变化,而对外界的进程一无所知。这样让容器内的进程运行在一个独立的 系统环境中,以此达到隔离的目的

事实上,subuid与subgid的作用,是定义一个可映射进Container的uid的range,在docker/podman中,会将subuid中定义的range中的一个映射至容器中的uid 0(root),这样映射后,容器中的root可以具有其自己的权限但是他的namespace仍然是宿主机中当前用户的namespace,也就是在宿主机中仅有当前用户的权限。

回过头来再看问题,明显的报出来是/etc/subuid中不存在一个可以映射入容器的范围,查看该文件,果然是空空如也,那么解决起来就很简单了,给他一个range即可

echo "当前用户名:110000:65536" > /etc/subuid
echo "当前用户名:110000:65536" > /etc/subgid

echo的内容解释为“在当前用户的namespace中有65536个子用户,子用户的ID是从110000-175535”, 而这些用户ID映射进容器后就是ID为0-65535的用户,subgid和subuid意义相似,在此不在赘述。修复后,再试一下,果然问题消失了。

╰─➤  podman run -it debian:latest                                                                                                     130 ↵
Trying to pull docker.io/library/debian:latest...Getting image source signatures
Copying blob 6f2f362378c5 done
Copying config e1de74e67c done
Writing manifest to image destination
Storing signatures
root@cc96213f30a2:/# 

这里想扯两句:
现在网络上关于podman的相关资料较少,其实大部分问题可以参考Docker的相关资料,podman实现了docker绝大多数的api(swarm除外),所以在大部分问题上docker的资料仍然具有其参考价值。

本文源自亲身经历,若有错误,还请指出。(请后面拿鸡蛋和西红柿的兄弟先坐下,谢谢)