What is the purpose of defining VOLUME mount points in DockerFile rather than adhoc cmd-line -v?

advertisements

I understand that using the VOLUME command within a Dockerfile, defines a mount point within container.

FROM centos:6
VOLUME /html

However I noticed that without that VOLUME definition, it's still possible to mount on that VOLUME point regardless of defining it

docker run -ti -v /path/to/my/html:/html centos:6

What is the purpose of defining VOLUME mount points in the dockerfile? I suspect it's for readability so people can read the Dockerfile and instantly know what is meant to be mounted?


VOLUME instruction used within a Dockerfile does not allow us to do host mount, that is where we mount a directory from the host OS into a container.

However other containers can still mount into the volumes of a container using the --from-container=<container name>, created with the VOLUMES instruction in the Dockerfile