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

后端 未结 2 712
梦如初夏
梦如初夏 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: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 -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.

提交回复
热议问题