What is the right way to add data to an existing named volume in Docker?

You can certainly copy data directly into /var/lib/docker/volumes/my-jenkins-volume/_data, but by doing this you are:

  • Relying on physical access to the docker host. This technique won’t work if you’re interacting with a remote docker api.

  • Relying on a particular aspect of the volume implementation would could change in the future, breaking any processes you have that rely on it.

I think you are better off relying on things you can accomplish using the docker api, via the command line client. The easiest solution is probably just to use a helper container, something like:

docker run -v my-jenkins-volume:/data --name helper busybox true
docker cp . helper:/data
docker rm helper

Leave a Comment