When bind mounts are files coming from your host machine, volumes are something more like the nas of docker.
- Bind mounts are files mounted from your host machine (the one that runs your docker daemon) onto your container.
- Volumes are like storage spaces totally managed by docker.
You will find, in the literature, two types of volumes:
- named volumes (you provide the name of it)
- anonymous volumes (usual UUID names from docker, like you can find them on container or untagged images)
Those volumes come with their own set of docker commands; you can also consult this list via
docker volume --help
You can see your existing volumes via
docker volume ls
You can create a named volume via
docker volume create my_named_volume
But you can also create a volume via a
version: "3.3" services: mysql: image: mysql volumes: - type: volume source: db-data target: /var/lib/mysql/data volumes: db-data:
Where this is the part saying please docker, mount me the volume named db-data on top of the container directory /var/lib/mysql/data
- type: volume source: db-data target: /var/lib/mysql/data
And this is the part saying to docker please create me a volume named db-data
Docker documentation about the three mount types: