4

I'm transitioning my current Jenkins server to implement Docker. Following the guide on github https://github.com/jenkinsci/docker, I was able to successfully launch jenkins with the command:

docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

I'm not sure how to view/access the data in my container/volume through file explorer. Is it only accessible through docker inspect? The guide in GitHub says I should avoid using a bind mount from a folder on the host machine into /var/jenkins/home. Is there another way to view and access my jenkins jobs?

ChipNugget
  • 363
  • 1
  • 7
  • 17
  • It says that you should avoid it because of potential file permission problems, that can be solved by granting those permisionss to jenkins user on host machine. However to inspect your files on host machine, as far as I know, you can only use bind mounts to watch your files in explorer. – Michał Krzywański May 09 '19 at 18:16
  • I agree – use "bind mounts," or better yet, "volumes." In any case, make the docker software work for you, and do things "its way." Play along with the illusion ... – Mike Robinson May 09 '19 at 18:37
  • For Windows + docker + WSL2, [this SO answer worked for me.](https://stackoverflow.com/a/64418064/556078) – Max Cascone Nov 11 '20 at 18:26

2 Answers2

4

As you can see in the Jenkins CI Dockerfile source code
/var/jenkins_home is declared as a VOLUME.
It means that it can be mounted on the host.
enter image description here

Your command mounts a docker volume to it but you could also mount a path on your host.
For example:

docker run -p 8080:8080 -p 50000:50000 -v ~/jenkins_home:/var/jenkins_home jenkins/jenkins:lts

On Windows hosts, you might have to create the directory first.

You can change ~/jenkins_home to whatever suites your host environment but that is a folder that you can easily navigate and inspect.

You can also still use the web interface available on the porta that you map on the host.

Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88
Mihai
  • 9,526
  • 2
  • 18
  • 40
  • If I wanted the path to my local host to be "C:/Jenkins", would the new command be docker run -p 8080:8080 -p 50000:50000 -v /C:/Jenkins:/var/jenkins_home jenkins/jenkins:lts – ChipNugget May 09 '19 at 19:04
  • To be honest I haven't used Windows in about 10 years so I can't confirm. Probably it would be without the first "/". If the syntax is wrong you will get an error for sure. – Mihai May 09 '19 at 19:07
  • I had to first create a directory called Jenkins in my host machine. Then I used the command "docker run –name jenkinsci -p 8080:8080 -p 50000:50000 -v ~/Jenkins:/var/jenkins_home/ jenkins/jenkins:lts". It seems like it's properly binded since my host machine's Jenkins directory is now populated with the jenkins content. – ChipNugget May 09 '19 at 21:53
  • I'll add this to the solution for Windows users. Just out of curiosity did you try other locations for the Jenkins directory and it didn't work? On a Mac for example there are only certain paths where by default docker can create directories for mounting. Different paths need to me explicitly declared – Mihai May 10 '19 at 04:30
  • Regarding Windows - the slashes go the other way! However, ~ still works so it should be -v ~\jenkins_home:/var/jenkins_home to mount the container folder to a folder on your host. – Tim Mar 27 '20 at 12:41
  • Would like to add that if you are using docker-compose. You litterally need to create a folder with the name for the volume and run `chown -R 1000:1000 ./volume-folder-name`. Also be aware, if you have a user that is using 1000 for uid/guid, they will own this folder. – Dave Jan 10 '22 at 21:20
0

If you want see the data on a local host file system you can use bind mounts instead of volume, it will sync all the data from the jenkins_home folder to your local host file system. For example: docker run -p 8080:8080 \ --name jenkins \ --mount type=bind,source="$(pwd)"/jenkins_home,target=/var/jenkins_home \ jenkins/jenkins for more clarification on bind mounts and volumes please follow this link. https://docs.docker.com/storage/bind-mounts/