docker: user namespace

One of the problem I met yesterday is that I add my user on GPU server to the docker group and run a DL docker container. Although I once firmly believed that the root in docker is virtual for the real server, it turned out I am wrong. And the bad result was that I occupied some of the GPUs exclusively, and terminated the running training process of the others with root privilege (who does not develop the habit to store its model after a specific number of epochs).

Therefore I was asked to run docker container without using root.
Before I made any changes, if you run some command in a docker container, and when you watch it on the real server, you will find the owner of that process is root.

ping www.google.com # command I uses for testing

After I made the changes, when I run the command in a docker container, in real server, it shows the uid of the user I set. Here is what I have done

Reference: Isolate containers with a user namespace

Step 1
Change the /etc/docker/daemon.json
from

{
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}

to

{
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    },
    "userns-remap": "default"
}

I chose userns-remap to be default merely for convenience. You can choose the user you like according to the format in reference.

Step 2
Restart docker service (It will delete all the existing images and containers)

systemctl restart docker

And there are some examination steps for these changes, it is in the Enable userns-remap on the daemon section (step 2 - step 5) in reference.

Once all of these have been done, when you run programs in container, although in docker it shows the user is root, in real server, the user is dockremap (under default case).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值