If we start a container that creates a new volume, or mount an empty directory to a destination in the container that contains files, then the files in the destination are copied into the volume or empty directory.
It means that with the following image:
FROM busybox
RUN echo "foo" > /data/bar
VOLUME /data
CMD ["/bin/sh"]
I would have a file bar in /tmp/my-temp-dir?
I don't know for Docker volumes but I doubt the container's /data/bar file which was created during the docker build (making /data/bar part of the Docker image basically) would be back-copied into host's /tmp/my-temp-dir directory...
Usually when you mount host's /tmp/my-temp-dir as container's /data/bar, any content of container/image's /data/bar is replaced. That's why so many images have a setup/fill part in their entrypoint's script.
I don't understand that part:
It means that with the following image:
Built and executed as follows
I would have a file
bar
in/tmp/my-temp-dir
?I don't know for Docker volumes but I doubt the container's
/data/bar
file which was created during thedocker build
(making/data/bar
part of the Docker image basically) would be back-copied into host's/tmp/my-temp-dir
directory...Usually when you mount host's
/tmp/my-temp-dir
as container's/data/bar
, any content of container/image's/data/bar
is replaced. That's why so many images have a setup/fill part in their entrypoint's script.You are correct, and I have edited the article to reflect this. Thank you.