How to properly start Docker inside Jenkins that is also running in Docker

I’m trying to run Docker inside a Jenkins container that is also running in Docker (i.e. Docker in Docker). What I want to know is how to properly start the Docker service when booting Jenkins. The only solution I’ve found today is to build my own Jenkins image based on the official Jenkins image but change the jenkins script loaded by the entry point to also start up Docker:

# I've added this line just before Jenkins is started from the script:
sudo service docker start
# I've also removed "exec" from the original file which used "exec java $JAVA_TOPS ..." but that didn't work
java $JAVA_OPTS -jar /usr/share/jenkins/jenkins.war $JENKINS_OPTS "$@"

This works when I run (using docker run) a new container but the problem is that if I do (docker start) on stopped container the Docker service is not started.

  • Docker: Direct subdomains to specific containers
  • Is there any reason to favour concatenated RUN directives over RUNning a script?
  • Exclude starting some containers with Docker Compose
  • Sensu-Client inside Docker container
  • Error when trying to run a meteor app in docker using meteorhacks:meteord
  • Linode/lamp + docker-compose
  • I strongly suspect that this is not the right way to start my Docker service. My plan is to perhaps use supervisord to start Jenkins and Docker separately (I suppose container linking is out of the question since Docker should be executed as a service on the same container that Jenkins is running on?). My concern with this approach is that I’m going to lose the EntryPoint specified in the Jenkins Dockerfile which allows me to pass arguments to the Jenkins container when starting the container, for example:

    docker run -p 8080:8080 -v /your/home:/var/jenkins_home jenkins -- <jenkins_arguments>

    Does anyone have any recommendations on a good way to solve this preferably by not forking the official Jenkins image?

  • How to copy a file from container to host using copy in docker-py
  • Run two processes in a single docker container or two containers connecting to the same DB?
  • Is there a way to access a running docker container on a remote server from my local development enviroment(Sublime)
  • Why are docker layer IDs now hidden with the new storage model?
  • docker not found with docker:dind + google/cloud-sdk
  • Spawn a new process in docker container which image is built from scratch
  • One Solution collect form web for “How to properly start Docker inside Jenkins that is also running in Docker”

    I’m pretty you cannot do that.

    Docker in Docker doesn’t mean you have to run docker inside docker with 3 level : host > First level container > Second Level Container

    In fact, you just need to share docker with host, and this is your host who will run others containers.

    To do that, you have to mount volume with -v parameter

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

    with this command, when you will docker run inside you jenkins container, the docker client will communicate with docker deamon from your host in order to run new container.

    To do that, you should run your jenkins container with privileged


    To resume, here is the full command line

    docker run -d -v /var/run/docker.sock:/var/run/docker.sock --privileged myimage

    And you you don’t need to create a new jenkins image for that.

    Hoping to have helped you

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.