Docker中启动Docker问题

尝试在Docker 的Centos容器中继续起个dokcer来测试,但是在容器中运行任何docker命令,如docker ps,都会报错:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

意思Docker没启动,然后尝试去启动:

service docker start

还是

systemctl start docker

都会报错:

System has not been booted with systemd as init system (PID 1). Can’t operate.

然后查看init.d下只有readme,也没有其他启动命令

最后研究一圈发现是Docker内不支持继续起Docker,

其实也很好理解,如果可以一直套娃,岂不是无穷无尽。

You can’t () run Docker inside Docker containers or images. You can’t () start background services inside a Dockerfile. As you say, commands like systemctl and service don’t (*) work inside Docker anywhere. And in any case you can’t use any host-system resources, including the host’s Docker socket, from anywhere in a Dockerfile.

You need to redesign this Dockerfile so that it only installs the software and makes no attempt to start it. Ideally a container would start only a single server, and would run it in the foreground as its CMD; otherwise you might depend on things like supervisord to have multiple servers if you must. If your application heavily relies on being able to start things in Docker, you might find it much easier to install in a virtual machine.

(*) Technically there are ways to do all of these things, but they’re all tricky and complicated and have implications (up to potentially giving your container unrestricted root access over the host, and your container startup actively reconfiguring some low-level host details).

参考:

https://stackoverflow.com/questions/51857634/cannot-connect-to-the-docker-daemon-at-unix-var-run-docker-sock-is-the-docke

你可能感兴趣的:(杂谈,docker,容器)