I have a Jenkins container defined in a docker-compose.yml file as follows:
jenkins:
image: jenkins/jenkins:lts
...
volumes:
- /srv/jenkins_workspace:/var/jenkins_home/workspace
- /usr/bin/docker:/usr/bin/docker
- /var/run/docker.sock:/var/run/docker.sock
...
This Jenkins container runs a Pipeline which, among other things, launches Docker containers. The issue I'm facing is that sometimes the working directory inside the Docker container does not reflect the changes that should have been made in Jenkins. Here's an example of how a Docker container is launched from the Pipeline:
script : "docker run -i ... -v ${workspace_dir}:/scripts ..."
I've noticed that /srv/jenkins_workspace is a volume mounted on the host but is not a remote directory, so I'm ruling out issues related to networked file systems.
My hypothesis is that the issue lies in how the volumes are being synchronized between the Jenkins container and the Docker containers it launches.
After consulting with Chat GPT, I've been proposed to use the propagation: rshared option on the Jenkins volume to ensure that mounts propagate between the host and the containers.
volumes:
- type: bind
source: /srv/jenkins_workspace
target: /var/jenkins_home/workspace
bind:
propagation: rshared
Questions:
- Is my approach using propagation: rshared correct for solving this synchronization issue?
- Is there a better way to handle this kind of synchronization problems between containers?