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?
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.
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.
@crodock, I faced the same problem. This is how I resolved it. In short, I place --init when starting container and I use custom script as the entrypoint.
Dockerfile:
FROM docker:dind
CMD /dump/startup.sh
Create a script file /share/my-folder-with-script/startup.sh that will run sshd and original dockerd-entrypoint.sh:
#!/bin/sh
/usr/sbin/sshd
dockerd-entrypoint.sh
Build image: docker build -t dockerdev .
Run container: docker run --init --privileged --name test-container -d -v /share/my-folder-with-script:/dump:ro dockerdev