As illustrated in "Understanding “VOLUME
” instruction in DockerFile
", a VOLUME
in Dockerfile creates a mount point within the container.
FROM ubuntu
RUN mkdir /myvol
RUN echo "hello world" > /myvol/greeting
VOLUME /myvol
This Dockerfile results in an image that causes docker run to create a new mount point at /myvol
and copy the greeting file into the newly created volume.
This was originally done for different containers to mount and access data from other containers.
See docker run --volumes-from
This is different from data persistence, where you want runtime session data to persist on disk.
For that, see "Manage data in Docker", where you can, at runtime, mount docker volumes, or Host folders (bind mounts), or tmpfs (for writing a large volume of non-persistent state data in the host system’s memory only, for performance, but without persistence)

NGiNX by default won't share data with other containers, so does not declare VOLUME
in its Dockerfile.
How about NGiNX ? I see static files are at /usr/share/nginx/html
but when I cd to this location from host cli it says directory not found, but when I cd from bash mode when executing container in interactive mode this path is displayed
It is meant to receive data from host through bind mount:
docker run --name mynginx \
-v /var/www:/usr/share/nginx/html:ro \
-v /var/nginx/conf:/etc/nginx:ro
-P -d nginx
Those data are "ro
" (read-only) within the container.
/usr/share/nginx/html
is a path from within the container, which is why, if you cd
to it on the host, you would not find it.