如果使用/ usr / sbin / init启动容器,则docker容器无法连接到docker守护程序

时间:2020-04-09 06:54:45

标签: docker centos7 daemon

sudo docker run -it --name="cms_docker_without_init_with_port" --privileged=true --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /home/cms/iris4_build:/home/cms/iris4_build -v /home/cms/jenkins:/home/cms/jenkins -v /home/cms/bin:/home/cms/bin -v /home/cms/cmn:/home/cms/cmn -v /home/cms/wls/bin:/home/cms/wls/bin -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -p 22000:22 artifact.oocl.com/fwk/cms_docker:1

我使用以上命令启动docker容器,cms_docker可以连接到目标VM中的docker守护进程。 容器内有contos7,我想启动sshd服务。我在docker官方文档中发现,启动容器时必须添加/usr/sbin/init

https://github.com/docker-library/docs/tree/master/centos#dockerfile-for-systemd-base-image

因此,我在启动容器时添加了"/usr/sbin/init"。命令如下:

sudo docker run -it --name="cms_docker_without_init_with_port" --privileged=true --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /home/cms/iris4_build:/home/cms/iris4_build -v /home/cms/jenkins:/home/cms/jenkins -v /home/cms/bin:/home/cms/bin -v /home/cms/cmn:/home/cms/cmn -v /home/cms/wls/bin:/home/cms/wls/bin -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -p 22000:22 artifact.oocl.com/fwk/cms_docker:1 /usr/sbin/init

但是在我添加/usr/sbin/init以启动容器之后,cms_docker无法连接到docker守护程序。

enter image description here

我需要启动sshd服务,还需要cms_docker连接到docker守护程序。但是现在看来有冲突。你有解决这个的主意吗?

0 个答案:

没有答案