Docker – How to persist all Jenkins data on an EBS volume in docker

amazon ec2amazon-ebsamazon-web-servicesdocker

I have the Docker official jenkins repo running on an Ubuntu instance. In that document, it suggests a way to create a volume as a way to isolate all Jenkins data file.

The EC2 instance has the root volume and a second volume at /dev/xsdf:

NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   8G  0 disk
└─xvda1 202:1    0   8G  0 part /
xvdf    202:80   0  10G  0 disk

IF have tried mounting that volume as /var/jenkins_home in Ubuntu, and then referencing it at run time:

docker run --restart=always -p 8080:8080 -p 50000:50000 -v \
/home/ubuntu/jenkins_home:/var/jenkins_home -w /var/jenkins_home jenkins/jenkins:lts

It runs fine, but I do not see any files on the host in /var/jenkins_home

Is there another(Correct) way to mount a EBS volume on the host and use it for the Jenkins data volume?

I would like to be able to backup it by taking a snapshot of the volume and allow the data to persist between restarts.

Thanks

Best Answer

If I'm understanding your question correctly it seems like you just have your volume syntax backwards. Think of the syntax like so:

-v /path/to/host/directory:/path/to/directory/inside/container

So in your case /var/jenkins_home is the correct directory inside the container, but you'd need to be looking in /home/ubuntu/jenkins_home currently to see the data from the container.

Here's a working example on my laptop:

[10:46 PM]~/Desktop ➭ mkdir jenkins_test
[10:46 PM]~/Desktop ➭ cd jenkins_test/
[10:46 PM]~/Desktop/jenkins_test ➭ docker run --rm -it --name jenkins \
➭ -p 8080:8080 \
➭ -p 50000:50000 \
➭ -v /Users/jadametz/Desktop/jenkins_test:/var/jenkins_home \
➭ jenkins/jenkins:lts

...

[10:52 PM]~/Desktop/jenkins_test ➭ ls -lh
total 80
-rw-r--r--   1 jadametz  staff   1.6K Aug 28 22:48 config.xml
-rw-r--r--   1 jadametz  staff   102B Aug 28 22:48 copy_reference_file.log
-rw-r--r--   1 jadametz  staff   159B Aug 28 22:48 hudson.model.UpdateCenter.xml
-rw-------   1 jadametz  staff   1.7K Aug 28 22:48 identity.key.enc
drwxr-xr-x   3 jadametz  staff   102B Aug 28 22:48 init.groovy.d
-rw-r--r--   1 jadametz  staff    94B Aug 28 22:48 jenkins.CLI.xml
-rw-r--r--   1 jadametz  staff   1.7K Aug 28 22:50 jenkins.install.InstallUtil.installingPlugins
-rw-r--r--   1 jadametz  staff     6B Aug 28 22:48 jenkins.install.UpgradeWizard.state
drwxr-xr-x   2 jadametz  staff    68B Aug 28 22:48 jobs
drwxr-xr-x   3 jadametz  staff   102B Aug 28 22:48 logs
-rw-r--r--   1 jadametz  staff   907B Aug 28 22:48 nodeMonitors.xml
drwxr-xr-x   2 jadametz  staff    68B Aug 28 22:48 nodes
drwxr-xr-x  51 jadametz  staff   1.7K Aug 28 22:49 plugins
-rw-r--r--   1 jadametz  staff   129B Aug 28 22:50 queue.xml
-rw-r--r--   1 jadametz  staff    64B Aug 28 22:48 secret.key
-rw-r--r--   1 jadametz  staff     0B Aug 28 22:48 secret.key.not-so-secret
drwx------  11 jadametz  staff   374B Aug 28 22:48 secrets
drwxr-xr-x   5 jadametz  staff   170B Aug 28 22:48 updates
drwxr-xr-x   3 jadametz  staff   102B Aug 28 22:48 userContent
drwxr-xr-x   3 jadametz  staff   102B Aug 28 22:48 users
drwxr-xr-x  25 jadametz  staff   850B Aug 28 22:48 war