user2340824
user2340824

Reputation: 2152

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

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?

Upvotes: 3

Views: 815

Answers (2)

Manuel J. Garrido
Manuel J. Garrido

Reputation: 2414

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

That's not right. In that case the volume is defined for an image, not for a container.

When a volume is defined in the Dockerfile, it's set for an image, so every container run from that image gets that volume defined.

If you define the volume in the command line (docker run -v ...) the volume is defined just for that specific container.

Upvotes: 0

askb
askb

Reputation: 6786

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

Upvotes: 1

Related Questions