简体   繁体   中英

Docker volume and mount

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.

  1. VOLUME in dockerfile only supports docker-managed volumes
  2. docker run --volume supports both docker-managed volumes and host path volumes
  3. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM