How do I install docker in a docker container?

This is my Dockerfile:

FROM golang
# RUN cat /etc/*release
RUN apt-get update
RUN apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"

RUN apt-get update
RUN apt-get -y install docker-ce
RUN docker run hello-world

      

Dockerfile golang is official, it is based on

Debian GNU/Linux 8 (jessie)

      

So, I wrote this Dockerfile by checking the installation steps from Docker Install Tutor (Debian)

But the way out

Step 8/8 : RUN docker run hello-world
 ---> Running in b183b8cc5d10
docker: Cannot connect to the Docker daemon at 
unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

      

How to solve this problem? I want to install Docker containers in a host Docker container.

+7


source to share


4 answers


Use Docker-in-Docker to accomplish this task. They have already solved many problems for you.



0


source


Try starting the Docker service before running any Docker command. Add this line

RUN bash service docker start

      



to your Dockerfile above this line:

RUN docker run hello-world 

      

0


source


The easiest way is to use the official Docker-in-Docker images from https://hub.docker.com/_/docker/ with the tag :dind

(which is the successor to the already mentioned Hendrikwha project ).

You definitely need to use a flag as well --priviledged

:

docker run --privileged --name yourDockerContainerNameHere -d docker:dind

      

With this, your Docker-in-Docker experiments should work - but be aware of the many obstacles you may have: https://jpetazzo.github.io/2015/09/03/do-not-use-docker- in- docker-for-ci /

0


source


I had a similar problem when trying to install Docker inside a Bamboo Server image. To solve this:

  1. first remove the line: RUN docker run hello-world from your Dockerfile

  2. The easiest way - just open a socket Docker, -v

    its a -v

    flag -v

    or a mounted volume by using Docker Compose

    :

docker run -v/var/run/docker.sock: /var/run/docker.sock...

0


source







All Articles