Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DinD with docker-compose #303

Closed
augustobmoura opened this issue Mar 24, 2021 · 4 comments · Fixed by #361
Closed

DinD with docker-compose #303

augustobmoura opened this issue Mar 24, 2021 · 4 comments · Fixed by #361
Labels
question Usability question, not directly related to an error with the image

Comments

@augustobmoura
Copy link

After following the guide in https://hub.docker.com/_/docker/ I wrote this docker-compose.yaml that should setup the same as the shell commands (if I understood it correctly):

version: "3.8"

services:
  dind:
    image: docker:dind
    privileged: true
    environment:
      DOCKER_TLS_CERTDIR: /certs
    networks:
      - docker
    volumes:
      - docker-certs-ca:/certs
      - docker-certs-client:/certs/client

  docker-client:
    image: docker
    environment:
      DOCKER_TLS_CERTDIR: /certs
    # Just loop at infinitum, we will get to this container by `docker exec`ing
    command: [sh, -c, "while sleep 1; do :; done"]
    networks:
      - docker
    depends_on:
      - dind
    volumes:
      - docker-certs-client:/certs/client:ro

volumes:
  docker-certs-ca:
  docker-certs-client:

networks:
  docker:

After running docker-compose exec docker-client docker version I got the following error, and I cannot connect to the dind docker from the docker-client:

Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:14:11 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Is there anything I'm missing in my docker-compose.yml?

Running the commands from the README manually I get the correct result

@tianon
Copy link
Member

tianon commented Mar 24, 2021

You're missing docker-entrypoint.sh which will set DOCKER_HOST (and TLS-related variables) appropriately:

$ docker-compose exec docker-client docker-entrypoint.sh docker version

@augustobmoura
Copy link
Author

Using docker-entrypoint shows another error:

Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:14:11 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
error during connect: Get https://docker:2376/v1.24/version: dial tcp: lookup docker on 127.0.0.11:53: server misbehaving

@tianon
Copy link
Member

tianon commented Mar 24, 2021

Ohhh, the difference is that your DinD container is named dind instead of docker -- after renaming that, I was able to get it working. 👍

Alternatively, I reverted back to your verbatim file, added hostname: dind to the Docker-in-Docker container, and added DOCKER_HOST: tcp://dind:2376 to the client container, and that also works.

@augustobmoura
Copy link
Author

Got it, so the problem is that I was not calling docker-entrypoint.sh which setups the env var DOCKER_HOST for a default tcp://docker:2376 url. Without the entrypoint I can just define the var to tcp://${docker_host}:${port} (and DOCKER_TLS_VERIFY DOCKER_CERT_PATH for tls support) and I'm good to go. Maybe we should put this on the README?

Thanks for the help!

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants