简体   繁体   中英

Docker compose v3: The difference between volume type mount and bind

I am using docker-compose syntax version 3 and want to use some volumes. The documentation on the long syntax for volumes states the following:

type : the mount type volume or bind

but never fully explains the difference. What is it?

bind is the simpler one to understand. It takes a host path, say /data and mounts it inside your container, say /opt/app/data . /data can be anything, probably mounted on NFS or it maybe a local host path. docker run -v /data:/opt/app/data -d nginx

volume mount is where you can use a named volume.

You would normally use a volume driver for this, but you can get a host mounted path using the default local volume driver something like the below:

docker volume create data docker run -d -v data:/opt/app/data nginx

The named volume can also be anonymous if you run just this: docker run -d -v /opt/app/data nginx

If you run docker volume ls , docker would have create an autogenerated long name for the anonymous volume.

In docker-compose, you would just use it as below:

web:
  image: nginx:latest
  volumes:
    /data:/opt/app/data
    data:/opt/app/data1

volumes:
  data:

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