Consider a Dockerfile that declares two volumes

FROM someimage
# ...
VOLUME ["/foo", "/bar"]

and a container started from that image, that does a bind mount for one of those volumes:

docker run --name mycontainer -d -v /some/path:/foo myimage

If I created a new image from that container using

docker commit mycontainer myexportedimage

both paths, /foo and /bar, will be excluded in the exported image.

How do I create a runnable (i.e. maintaining meta data from Dockerfile) image from mycontainer that includes the data from both paths, /foo (bind mounted) and /bar (volume as declared by Dockerfile), so if I exported the image to another Docker host, all data would be present?

  • That's the point of volumes. Don't put that in a volume if you want data to be on the image rather than on the volume. I recommend you to read some docker documentation. – Florin Asăvoaie Sep 9 '17 at 11:47
  • @FlorinAsăvoaie I know, but that's just the situation I have and need to handle – muffel Sep 9 '17 at 12:33
  • No, it is not. It is a situation where you need to understand how containers work and what is the difference between a volume and an image, and what the Linux "mount" command does. – Florin Asăvoaie Sep 9 '17 at 13:56
  • @FlorinAsăvoaie I was given the job to "rescue" containers from a server I have neither setup nor maintained until now, and now am looking for a possibility to somehow get along with the situation. I know the differences and what mount does. That's why I'm looking for a way (a script, a tool, ...) to somehow handle those containers and do my job. – muffel Sep 9 '17 at 14:01
  • If you need to move volumes, inspect the container to get the volume target, and move that. Also, don't declare volumes inside of a Dockerfile, that feature exists for historical reasons and only causes issues in current environments. – BMitch Sep 9 '17 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.