Could some one help me to understand the difference between:
VOLUME command in Dockerfile (image building layer)
and
The -v parameter and VOLUME keyword are almost the same. You can use -v to have the same behavior as VOLUME.
docker run -v /data
Same as
VOLUME /data
But also -v have more uses, one of them is where map to the volume:
docker run -v data:/data # Named volumes
docker run -v /var/data:/data # Host mounted volumes, this is what you refer to -v use, but as you can see there are more uses,
So the question is: what is the use of VOLUME in a Dockerfile?
The container filesystem is made of layers so writing there, is slower and limited (because the fixed number of layers) than the plain filesystem.
You declare VOLUME in your Dockerfile to denote where your container will write application data. For example a database container, its data will go in a volume regardless what you put in your docker run.
If you create a docker container for JBoss and you want to use fast filesystem access with libaio yo need to declare the data directory as a VOLUME or JBoss will crash on startup.
In summary VOLUME declares a volume regardless what you do in docker run. In fact in docker run you cannot undo a VOLUME declaration made in Dockerfile.
Regards