0

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.

Sato
  • 8,192
  • 17
  • 60
  • 115

1 Answers1

3
  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

cizixs
  • 12,931
  • 6
  • 48
  • 60
  • official docs pages changed. Can you please help to locate where it is written that "docker run --volume overrides dockerfile"? – Alex Martian Dec 02 '19 at 15:18