Sato
Sato

Reputation: 8602

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.

Upvotes: 0

Views: 3699

Answers (1)

cizixs
cizixs

Reputation: 13981

  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

Upvotes: 3

Related Questions