How to mount volume in a docker job inside a dockerized jenkins

1,046 views
Skip to first unread message

Nicolas Geraud

unread,
May 18, 2016, 4:14:12 AM5/18/16
to Jenkins Users
Hi all,

i'm using a dockerized jenkins (from jenkinsci/jenkins:2.2) and mounting the following volumes from my host :
volumes:
        - "/opt/jenkins:/var/jenkins_home"
        - "/var/run/docker.sock:/var/run/docker.sock"


I've created a job that launch a docker container to build some python files :
--Dockerfile
FROM python:3-onbuild
CMD [ "python" ]

docker command of my jenkins job :
$docker run --rm -v `pwd`:"/usr/src/myapp" graviteeio/python3 python src/main/python/package_bundles.py

But the result is :


Starting docker_package_bundle_and_publish_1
Attaching to docker_package_bundle_and_publish_1
[36mpackage_bundle_and_publish_1 | [0m python: can't open file './src/main/python/package_bundles.py': [Errno 2] No such file or directory
[36mdocker_package_bundle_and_publish_1 exited with code 2
[0mFinished: SUCCESS

This is working fine on a classic jenkins, but not on a dockerized jenkins. I've googled this error and it seems that mounting a volume inside a container with an already mounting volume doesn't work.

I think that some of you have already test the same use case so, how to do that ?

Thanks for any clue.
I need to test a data volume instead of mounting a host volume.

nicolas de loof

unread,
May 18, 2016, 4:28:05 AM5/18/16
to jenkins...@googlegroups.com
For this to work, you'll need the host path to be the exact same as the jenkins container path, i.e. not use /opt/jenkins but /var/jenkins_home on host
so `pwd` will resolve to some /var/jenkins_home/... subfolder that make sense to be mounted from host into your side container

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f847d41e-3b28-4b2b-b61e-ca0bf2927e5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolas Geraud

unread,
May 18, 2016, 4:34:31 AM5/18/16
to Jenkins Users
Thanks for the quick answer, I'll test this tonight.

Do you have any blog post (or perhaps i've missed a "Quoi de neuf Docker" episode) which explain why it works like this ?

nicolas de loof

unread,
May 18, 2016, 5:01:33 AM5/18/16
to jenkins...@googlegroups.com
The reason it works like this is the bind mount is done from host, so need a valid fully qualified host path, but the `pwd` command is ran inside jenkins container, so resolves to container filesystem.
A possible alternate approach is for you to rely on " --volumes-from $(hostname) ", as a container hostname defaults to it's ID. As a result, your second container will share /var/jenkins_home with jenkins master. Then you can run some commands using $workspace as a valid path in both containers :

docker run --rm --volumes-from $(hostname) graviteeio/python3 python ${WORKSPACE}/package_bundles.py

Nicolas Geraud

unread,
May 18, 2016, 7:11:42 PM5/18/16
to Jenkins Users
Ok, with some tests I know understand how "sibling containers" work.

thanks for your help
Reply all
Reply to author
Forward
0 new messages