How to run docker container inside docker (DIND)?

2019-07-05 02:46发布

I am trying to run a container inside another container using Docker inside docker https://hub.docker.com/_/docker.

When I run the following:

docker run --privileged docker:stable-dind docker run hello-world

I get the following error message:

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

I must be missing something, how can I run docker inside docker?

标签: docker
1条回答
贼婆χ
2楼-- · 2019-07-05 03:37

I don't think you can do this in a one-liner (others might correct me). However, as explained at hub.docker.com/_/docker/, you can start the a docker-in-docker container as a background daemon (-d) and then start other containers inside.

To start the parent container, run

docker run -d --name some-docker --privileged docker:stable-dind

The name some-docker is arbitrary. It will be used to identify this container later on. To start a container inside, run

docker run  --link some-docker:docker docker run hello-world

The --link option exposes the network ports of the parent container and sets environment variables, such that the inner container uses docker from the dind image.

查看更多
登录 后发表回答