Yesterday I was trying to deploy a Jenkins on a Linux machine. From my past experience, the official Jenkins Docker image works very well, I can build all of my projects without doing any messy configuration.

However, the latest Jenkins Docker image seems to be a simplified version, as in most of the plugins and pre-configured things are gone…


With pipeline script

                docker {image 'node'}
                sh 'npm install'
                sh 'npm run build'

Jenkins complains that docker is not found. It turns out that jenkins:lts image does not support docker in docker by default.


After some research, the old way of making docker in docker happen is to simply bind mount host’s docker CLI binary and docker’s communication socket in to Jenkins container, so that the container can use host’s docker to build.

However one blog post pops up quite often during my research, saying that docker has changed in a way that binding only the CLI binary to the container is not enough(even dangerous). So as of Jun/2019 the recommended way is to install docker CLI(CLI only, no daemon) inside the container and bind mount the communication socket, so that the program(in this case, Jenkins) in container is able to use its own docker CLI binary to call the host’s daemon.

Code/Config is shown in the next section.


I’ve posted my Dockerfile and docker run command on Github gist.

Link to the gist

For easy reading, I just copy it here.


The formatting here looks messed up, refer the link above…

FROM jenkins/jenkins:lts
# if we want to install via apt
USER root
  && tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 \
                 -C /usr/local/bin docker/docker \
  && rm docker-${DOCKERVERSION}.tgz
RUN groupadd docker
RUN usermod -aG docker jenkins
RUN chmod -v a+s $(which docker)
# drop back to the regular jenkins user - good practice
USER jenkins

docker run command

docker run -d \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 8089:8080 -p 50000:50000 \
-e JENKINS_OPTS="--prefix=/devops" \
--name my-jenkins \

Leave a Reply

Your email address will not be published. Required fields are marked *