Docker Community Forums

Share and learn in the Docker community.

Docker fails to mount volume inside Jenkins scripted pipeline

I’m working on a CI Jenkins build with scripted pipeline. From Jenkins on one machine, I’m connecting with already configured Jenkins slave on another machine (M2). I’m able to successfully execute docker commands within the jenkins slave, however it seems that docker is unable to mount the volumes from the slave to the freshly started docker image.

node('testImage') {
   ... //do some job including creation of volumes within the "testImage" container
    stage('Run WildFly instances') {
        //run wildfly relevant
        sh "docker run -d --restart=unless-stopped \
           -v /some/path/to/volume/in/jenkins/slave/container:/some/path/to/volume/within/wildfly14/container \
           -p 8380:8080 \
           -p 9380:9990 \
           -e JAVA_OPTS='-Xms256m -Xmx512m' \
           --name wildfly14 \

/some/path/to/volume exists within the jenkins slave docker image, because it’s created within the lifecycle of the pipeline, but the wildfly14 container that I’m trying to run is unable to access /some/path/to/volume, because when I run

docker exec -it wildfly14 ls -lR /some/path/to/volume/within/wildfly14/container

it’s simply empty. Any suggestions on why is it even happening? I’ve noticed that the docker containers are set up outside of the jenkins slave container, on the actual machine (M2). Could it be the reason that docker tries to map a volume from outside of the container (/some/path/to/volume) on M2 instead of the location within the jenkins slave?

Docker plugin volume mounts has fixed the problem. I’ve forgot to add these