I'm not very clear about the behavior of volume and mount
1. no volume, no mount
FROM centos
RUN mkdir /data
CMD ["bash"]
docker build -t vm .
docker run --rm vm mkdir /data/new
I'm sure /data/new will not exist in host disk
2. no volume, with mount
FROM centos
RUN mkdir /data
CMD ["bash"]
docker build -t vm .
docker run --rm -v /tmp:/data vm mkdir /data/new
/tmp/new exists after container delete without VOLUME, what is the point of VOLUME?
3. with volume, no mount
FROM centos
RUN mkdir /data
VOULME /data
CMD ["bash"]
docker build -t vm .
docker run --rm vm mkdir /data/new
Will dir new
exist in host disk?
4. with volume, with mount
FROM centos
RUN mkdir /data
VOULME /data
CMD ["bash"]
docker build -t vm .
docker run --rm -v /tmp:/data vm mkdir /data/new
Dir new
will exist.
VOLUME
in dockerfile only supports docker-managed volumes docker run --volume
supports both docker-managed volumes and host path volumes docker run --volume
overrides dockerfile There is more explanation on official docker documentation .
Also a helpful post here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.