I created a Dockerfile to run Docker inside Docker:
FROM ubuntu:16.04
RUN apt-get update && \\
apt-get install -y \\
apt-transport-https \\
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
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.