Running Docker inside Docker container: Cannot connect to the Docker daemon

后端 未结 2 711
梦如初夏
梦如初夏 2021-01-21 04:02

I created a Dockerfile to run Docker inside Docker:

    FROM ubuntu:16.04
RUN apt-get update && \\
    apt-get install -y \\
    apt-transport-https \\
          


        
相关标签:
2条回答
  • 2021-01-21 04:23

    The recommendation I received for this was to use the -v parameter in docker run to map the docker socket between containers like this:

    -v /var/run/docker.sock:/var/run/docker.sock
    
    0 讨论(0)
  • 2021-01-21 04:28

    If you really want to run a Docker container inside an other Docker container, you should use already existing images provided by Docker (https://hub.docker.com/_/docker) instead of creating your own base image : choose images tagged as dind (docker in docker) or <docker_version>-dind (like 18.09.0-dind). If you want to run your own image (not recommended though), don't forget to run it with --privileged option (that's why you get the error).

    Example with docker official images :

    # run Docker container running Docker daemon
    docker run --privileged --name some-docker -d docker:18.09.0-dind
    
    # run hello-world Docker image inside the Docker container previously started
    docker exec -i -t some-docker docker run hello-world
    

    Nevertheless, I agree with @DavidMaze comment and the reference blog post he referred to (Do not use Docker-in-Docker for CI) : Docker-in-Docker should be avoided as much as possible.

    0 讨论(0)
提交回复
热议问题