What is the purpose of the VOLUME instruction in a Dockerfile?

Shane asked:

In the documentation it says that the VOLUME instruction creates a mout point but I created a image using

FROM alpine
RUN mkdir /myvol
RUN echo "hello world" > /myvol/greeting

and I was able to mount /myvol or any any other path on the containers filesytem using docker run -v vol:/myvol myimage and was able to see the data there in /var/lib/docker/vol/_data on the host machine.

What difference would adding VOLUME myvol to the Dockerfile make?

My answer:

The obvious use of VOLUME is to populate a new persistent volume with data supplied by your container. Regardless of what sort of application you are deploying, there’s almost always some initial data you need to start with. The documentation makes clear that this copy only takes place when the volume is newly created.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.