Docker Community Forums

Share and learn in the Docker community.

Docker in docker not running when using official docker dind image

I am trying to created my own docker image.
In my docker file I used official docker dind image
FROM docker:20.10.7-dind

I install everything else I need inside Dockerfile then create container using that dockerfile and start it.
I shell into it using docker exec -it however when I try to run docker ps or any other command I receive the following error:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Should docker already be started if I used dind image? Or I am not understanding this properly.
My CMD to start container is
CMD ["/usr/sbin/sshd", “-D”, “-e”]
because I also want to start ssh server.

How can I start both ssh server and docker so that docker commands can be used inside container?

Thank you.

Is it ssafe to assume that the dind container is started with --privliged flag?

It is. I run it with the following command:
docker run --privileged dind:latest

Did you check the output of ps (literaly, not docker ps) inside the container to check if dockerd is actualy running?

my guess: you override the ENTRYPOINT instruction or your CMD instruction causes the entrypoint script to skip the start of the docker engine inside the container.

No it is not running.
ps command outputs:

1 root 0:00 sshd: /usr/sbin/sshd -D -e [listener] 0 of 10-100 startups
7 root 0:00 bin/bash
36 root 0:00 ps

I also use entryopoint, that is correct.
And if that is true for my entrypoint or CMD, any idea on what to do in order to resolve it?

Remove your CMD instruction and verify if my assumption is true. Then you know the problem is within your CMD instruction… I neither use a dind container, nor would I ever (repeat in an endless loop!) run an sshd inside a container.