Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run docker:dind to start with a shell

I want to run docker:dind and get a shell.
If I run docker run --privileged docker:dind sh it just exit.
The workaround is to run: docker run -d --privileged docker:dind
it starts in the background and then I can run docker exec -it <container> sh and get a shell.

But I want that it will start with a shell.
I created a Dockerfile:

FROM docker:dind
ENTRYPOINT sh  

I built it:
docker build -t dind2 -f Dockerfile .

When I run docker run --rm -it --privileged dind2 I get a shell but when I tried to run simple container docker run busybox echo hi it failed with:

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

Any idea how make docker:dind start with a shell without the workaround of running it in the background and then using exec to get a shell.

like image 519
E235 Avatar asked Oct 17 '22 08:10

E235


1 Answers

Just like Andreas Wederbrand said. you can just

docker run -it docker:dind sh

and if you want to use Dockerfile. Just write like this.

FROM docker:dind
CMD ["sh"]

It shouldn't overwrite ENTRYPOINT. You can try to inspect docker:dind image.

docker inspect docker:dind

you can see entrypoint is a shell script file.

"Entrypoint": [
  "dockerd-entrypoint.sh"
   ],

of course, we can find this file in container. get inside the docker

docker run -it docker:dind sh

and then

cat /usr/local/bin/dockerd-entrypoint.sh

more about entrypoint you can see

https://medium.freecodecamp.org/docker-entrypoint-cmd-dockerfile-best-practices-abc591c30e21

like image 117
RicoChen Avatar answered Nov 15 '22 07:11

RicoChen