I am trying to run docker within docker. The sole purpose is experimental, I am by no means trying to implement anything functional, I just want to check how docker performs when it is run from another docker.
I start docker through boot2docker om my mac and then spin up a simple ubuntu image.
$ docker run -t -i ubuntu /bin/bash
I then go ahead and install docker as well as python.
root@aa9263c874e4: apt-get update
root@aa9263c874e4: apt-get install -y docker.io python2.7
It is able to connect to the internet, because it performs this apt-get. I then get the following error when I am trying to start a docker instance from within docker:
root@aa9263c874e4: sudo docker run -t -i ubuntu /bin/bash
2015/01/09 08:59:09 Post http:///var/run/docker.sock/v1.12/containers/create: dial unix /var/run/docker.sock: no such file or directory
Any idea what I missed? It seems weird that I get a post error because it seems to be able to connect to the internet via apt-get before.
I answered a similar question before on howto run a Docker container inside Docker.
To run docker inside docker is definitely possible. The main thing is that you
run
the outer container with extra privileges (starting with--privileged=true
) and then install docker in that container.Check this blog post for more info: Docker-in-Docker.
An excellent use case for this is described in this entry. The blog describes how to build docker containers within a Jenkins docker container.
So, I believe that your POST
problem has nothing to do with connecting to the internet since the container is trying to talk to the docker socket. To solve the problem, simply add the --privileged=true
flag on the outer container when starting it, like this:
docker run --privileged=true ...