Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run docker container inside docker (DIND)?

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?

like image 280
Jamesla Avatar asked Sep 01 '25 10:09

Jamesla


1 Answers

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.

like image 125
sauerburger Avatar answered Sep 04 '25 02:09

sauerburger