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.

  • Stop and restart containers with docker-compose
  • Unable to connect container port from localhost when network_mode: “bridge” (docker-compose)
  • What is the different between Docker bundles and docker-compose?
  • Docker run appears to ignore the name argument
  • failed to pull docker/whalesay from dockerhub,
  • Problems with RSelenium
  • 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?

  • Docker mount namespace
  • Customise apache.conf - set Timeout
  • concourse gradle java build CI
  • Which ca.crt does docker.sock use for docker pull?
  • Docker Container: Did anyone use G11DockerWp to clone WordPress site?
  • Why does using DOCKER_OPTS=“--iptables=false” break the DNS discovery for docker-compose?
  • 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.