- When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its full or relative path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.
- The file or directory does not need to exist on the Docker host already. It is created on demand if it does not yet exist.
- Both allow sharing contents amoung containers
- Prepopulated contents obsucured in case of Bind Mount while Volume sync the contents from containers to Docker host.
- Bind Propagation exixt only in Bind Mount.
- Unlike a bind mount, you can create and manage volumes outside the scope of any container.
- Create a volume:
$ docker volume create my-vol
--name devtest \
-v myvol2:/app \
nginx:latest
docker run -d \
-it \
--name devtest \
-v "$(pwd)"/target:/app \
nginx:latest