CentOS7.4中配置docker user namespace以及解决docker swarm集群监控问题

 

CentOS7.4中配置docker user namespace

1,安装docker

yum install docker

2,以用户shannyn(uid:1000,gid:1000)为例配置docker user namespace,在/etc/docker/daemon.json中,输入下面内容:

{

"userns-remap": "shannyn"

}

3,需要把host的uid和gid跟docker容器内的uid、gid做一个对应:

echo "shannyn:1000:65536" >> /etc/subuid

echo "shannyn:1000:65536" >> /etc/subuid

意思是容器内id为0的用户,将会映射到host上id为1000的用户,后面65536个用户也会跟着做映射。

4,把shannyn用户加入到docker群组里:

sudo usermod -aG docker shannyn

4,CentOS7的kernel默认关闭了user namespace,需要重新打开

grubby --args="namespace.unpriv_enable=1 user_namespace.enable=1" --update-kernel="$(grubby --default-kernel)"

echo "user.max_user_namespaces=15076" >> /etc/sysctl.conf

reboot

5,启动docker

systemctl start docker

6,检查容器用户是否映射成功

 

posted on 2019-01-14 17:17  shannyn  阅读(2175)  评论(0)    收藏  举报

导航