Cannot share data between volumes on different containers on Jenkins

Viewed 163

I am new at docker and I've been struggling with the following:

sh "docker network create grid${buildProperties}"
sh "docker run -d --net grid${buildProperties} --health-cmd=\"curl -sSL http://selenium-hub${buildProperties}:4444/wd/hub/status | jq -r '.status' | grep 0\" --health-interval=5s --health-timeout=1s --health-retries=10 --name selenium-hub${buildProperties} selenium/hub:3.141.59-radium"
sh "docker run -d --link selenium-hub${buildProperties}:selenium-hub --net grid${buildProperties} -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm --name chrome-node${buildProperties} selenium/node-chrome:3.141.59-20200525"


sh "docker build -t ui-tests-runner ."
sh "docker run -d --link selenium-hub${buildProperties}:selenium-hub --net grid${buildProperties} -e HUB_HOST=http://selenium-hub:4444/wd/hub -v DataVolume5:/src --name ui-tests-runner${buildProperties} ui-tests-runner"

sh "docker ps"

sh "docker run --rm -v DataVolume5:/datavolume5 ubuntu ls -l datavolume5"

I am trying to get data from ui-tests-runner${buildProperties} container from /src into DataVolume5 I am getting 0 files when I list the contents of datavolume5

However, if I try to do the same thing with chrome-node${buildProperties} /home I can see /seluser when I list the contents of datavolume5 which is expected.

sh "docker network create grid${buildProperties}"
sh "docker run -d --net grid${buildProperties} --health-cmd=\"curl -sSL http://selenium-hub${buildProperties}:4444/wd/hub/status | jq -r '.status' | grep 0\" --health-interval=5s --health-timeout=1s --health-retries=10 --name selenium-hub${buildProperties} selenium/hub:3.141.59-radium"
sh "docker run -d --link selenium-hub${buildProperties}:selenium-hub --net grid${buildProperties} -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm -v DataVolume5:/seluser --name chrome-node${buildProperties} selenium/node-chrome:3.141.59-20200525"


sh "docker build -t ui-tests-runner ."
sh "docker run -d --link selenium-hub${buildProperties}:selenium-hub --net grid${buildProperties} -e HUB_HOST=http://selenium-hub:4444/wd/hub --name ui-tests-runner${buildProperties} ui-tests-runner"

sh "docker ps"

sh "docker run --rm -v DataVolume5:/datavolume5 ubuntu ls -l datavolume5"

I tried numerous things that I found online, I checked permissions and that seems fine. The only thing I can think of what's different is that the ui-tests-runner${buildProperties} container is hosting a repository. I don't know what else to try. I have been struggling for a few days now.

This piece of code was taken from the pipeline bit in the Jenkinsfile

3 Answers

You have a race condition between these two commands:

sh "docker run -d ... -v DataVolume5:/src ... ui-tests-runner"

sh "docker run --rm -v DataVolume5:/datavolume5 ubuntu ls -l datavolume5"

The first command, with the -d option, will not stop. It will run the container in the background. The second command then runs while your ui-tests-runner container is starting up, and shows the folder before your tests have run.

Named volumes are also populated when first used with the image contents at that location. So when you use a different path that has contents inside your image at that location, you'll get files in the volume.

Once that initialization step is done and the volume is no longer empty, you'll only see files that are written to the volume by the process inside a container. You won't get changes from the image filesystem as images are redeployed since that path in the container is replaced by the contents of the persistent volume.

I presume you're creating DataVolume5 as a named volume, using docker volume create.
In which case you don't need to specify the absolute path, but docker volume inspect DataVolume5 will give you the path.

Try using a specific host directory as the shared volume instead.

docker run -d -v myVolume:/src ui-tests-runner
  1. first check DataVolume5 containes something after running ui-tests-runner command
  2. in the command docker run --rm -v DataVolume5:/datavolume5 ubuntu ls -l datavolume5 give absolute path of DataVolume5

Eg. docker run --rm -v /abs-path-to-directory/DataVolume5:/datavolume5 ubuntu ls -l datavolume5

Related