大网数据广告活动
服务器运维问答

Docker change existing stack to start with user namespace but keep images, volumes and containers

· 52CE 我爱测

To mitigate the problem with root access from a container to its host I like to start the docker service with a namespace as the docker docs suggest. This is how I did sudo adduser dockremap sudo sh -c 'echo dockremap:500000:6553…

问题原文

原帖链接 · toni · CC BY-SA 4.0

To mitigate the problem with root access from a container to its host I like to start the docker service with a namespace as the docker docs suggest. This is how I did

sudo adduser dockremap
sudo sh -c 'echo dockremap:500000:65536 > /etc/subuid'
sudo sh -c 'echo dockremap:500000:65536 > /etc/subgid'
sudo vim /etc/docker/daemon.json
   {
     "userns-remap": "dockremap"
   }
sudo service docker restart

While this leads to the desired behaviour of having root inside a container that is mapped to dockremap on the host, I cannot see all of the images and containers created earlier anymore.

Question: Is it possible to restart the docker daemon as shown but to keep all of my volumes, images and containers? If not what else can be suggested (docker rootless, apparmore groups <- hard to find a start)

已采纳解答

原帖链接 · BMitch · CC BY-SA 4.0

No, it is not possible. From Docker's documentation on user namespaces:

Enabling userns-remap effectively masks existing image and container layers, as well as other Docker objects within /var/lib/docker/. This is because Docker needs to adjust the ownership of these resources and actually stores them in a subdirectory within /var/lib/docker/. It is best to enable this feature on a new Docker installation rather than an existing one.

Docker would like to make this easier, but at the filesystem level, uid/gid's on files cannot be transparently mapped in a filesystem agnostic way. There are some efforts to get this functionality added and the progress is most visible with the rootless development. Things to look at include the efforts behind shiftfs, fuse-overlayfs, and similar projects.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-12-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。