generator-jhipster: Running Docker in the docker container fails with Cannot connect to the Docker daemon

  • Overview of the request

Add the ability to run docker from within the docker container, in order to successfully execute commands such as from within it:

./gradlew bootRepackage -Pprod buildDocker

Note that the docker container is started with:

docker run --name jhipster \
    -v $(which docker):/usr/bin/docker \
    -v /data/apps/jhipster/app/.m2:/home/jhipster/.m2 \
    -v /data/apps/jhipster/app/.gradle:/home/jhipster/.gradle \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /data/apps/jhipster/app:/home/jhipster/app \
    -v /lib64/libdevmapper.so.1.02:/usr/lib/x86_64-linux-gnu/libdevmapper.so.1.02 \
    -v /lib64/libudev.so.0:/usr/lib/x86_64-linux-gnu/libudev.so.0 \
    --privileged=true \
    -p 8080:8080 -p 3000:3000 -p 3001:3001 -d -t jhipster/jhipster

and /data/apps/jhipster/app is owned by id=1000.

  • Motivation for or Use Case

In order to use an already packaged jhipster dev container, but also do docker magic!

  • Browsers and Operating System

NA

  • Related issues

NA

  • Suggest a Fix The current state is that the user jhipster cannot contact the /var/run/docker.sock, because it isn’t in the docker group.

jhipster@uniqueid:~/app$ ls -lart /var/run/docker.sock srw-rw---- 1 root 979 0 Dec 15 16:36 /var/run/docker.sock

$ docker exec -it jhipster bash
jhipster@f65455ab5cfd:~/app$ docker info
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

in theory, a simple groupadd docker and -g docker in the Dockerfile should be enough.

groupadd jhipster && groupadd docker \ useradd jhipster -s /bin/bash -m -g jhipster -g docker -G sudo && \

I also noticed that sudo isn’t installed (not a default package anymore)

sudo groupadd docker
bash: sudo: command not found

I can contribute to this if you can point me to:

  1. how to rebuild this generator and test it
  2. how to execute commands as sudo in this container

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (16 by maintainers)

Most upvoted comments

Also I don’t think you need to add a docker group in the container. The docker daemon should use the permissions from the host. Just use in your container a uid that has permissions on the host.

@jmkhael you have a good idea here ! I think it would be OK to add the jhipster user to the docker group so that you can do a docker build from within docker. However some remarks :

  • Although sudo is not installed but you can log in as root with the -u 0 arg to the docker cli. -v $(which docker):/usr/bin/docker : this doesn’t work out of the box with Docker for Mac and for good reason, also it seems a bit dangerous. However, you can simply download the docker cli binary (extract it from the release tar here https://github.com/docker/docker/releases) and execute it. I just tried it and it works !