Correct usage of VOLUME in Dockerfile

Currently I have the line

VOLUME ["/home/data"]

in my Dockerfile, designed as a portal for data exchange between the host and container. To achieve that the user needs to use

docker run -it -v /somewhere_host:/somewhere_container <IMAGE>.

I can understand this mapping is not supported in Dockerfile because the host location will be different from case to case. But we should be allowed to specify a fixed mount point in the container, shouldn’t we? For instance

docker run -it -v /somewhere_host: <IMAGE>

will mount the /somewhere_host directory onto /home/data, if VOLUME ["/home/data"] is in the Dockerfile.

What’s the correct usage of VOLUME instruction, and if I’d like to achieve the above effect, what should I do?

This will become complicated if multiple volumes are defined in the Dockerfile. Why would someone want docker to decide where the volume should be mounted. Volumes are mounted for a specific reason and so isn’t it the right approach to explicitly define the volume?

And one more thing , if you mount a volume without mentioning the container path it will get mounted at the same path as the host has.

eg: docker run -it -v /my/host/vol busybox . This will mount host volume /my/host/vol to /my/host/vol inside the container.


Just because the volumes are mounted for a specific reason it makes sense to put them at specific locations, in the Dockerfile, not in the command line where you have to type in everytime (and you can’t be sure you type in exactly the same everytime you do so. )

I dont see the complication of multiple volumes, you just have to match them in order.
Lastly, what’s the point of having a VOLUME instruction in the Dockerfile if you have to do the same again in the commandline and override the Dockerfile definitions?