Jenkins Docker image, to use bind mounts or not? Jenkins Docker image, to use bind mounts or not? jenkins jenkins

Jenkins Docker image, to use bind mounts or not?


As commented, the syntax used is for a volume:

docker run -d -v jenkins_home:/var/jenkins_home -n jenkins ...

That defines a Docker volume names jenkins_homes, which will be created in:
/var/lib/docker/volumes/jenkins_home.

The idea being that you can easily backup said volume:

$ mkdir ~/backup$ docker run --rm --volumes-from jenkins -v ~/backup:/backup ubuntu bash -c “cd /var/jenkins_home && tar cvf /backup/jenkins_home.tar .”

And reload it to another Docker instance.

This differs from bind-mounts, which does involve building a new Docker image, in order to be able to mount a local folder owner by your local user (instrad of the default user defined in the official Jenkins image: 1000:1000)

FROM jenkins/jenkins:lts-jdk11USER rootENV JENKINS_HOME /var/lib/jenkinsENV COPY_REFERENCE_FILE_LOG=/var/lib/jenkins/copy_reference_file.logRUN groupmod -g <yourId>jenkinsRUN usermod -u <yourGid> jenkinsRUN mkdir "${JENKINS_HOME}"RUN usermod -d "${JENKINS_HOME}" jenkinsRUN chown jenkins:jenkins "${JENKINS_HOME}"VOLUME /var/lib/jenkinsUSER jenkins

Note that you have to declare a new volume (here /var/lib/jenkins), because, as seen in jenkinsci/docker issue 112, the official /var/jenkins_home path is already declared as a VOLUME in the official Jenkins image, and you cannot chown or chmod it.

The advantage of that approach would be to see the content of Jenkins home without having to use Docker.

You would run it with:

docker run -d -p 8080:8080 -p 50000:50000 \  --mount type=bind,source=/my/local/host/jenkins_home_dev1,target=/var/lib/jenkins \  --name myjenkins \  myjenkins:lts-jdk11-2.190.3sleep 3docker logs --follow --tail 10 myjenkins