Skip to content

Volumes vs bind mounts

Select an icon to see what it is.

Step 6 of 6

docker inspect shows both kinds

docker inspect lists each mount under Mounts, with a Type of volume or bind. A volume has a Name and a Driver. A bind mount has no Name, and its Source is the host path you chose.

$ docker inspect --format '{{json .Mounts}}' db
PrevNext

docker inspect (Mounts, two containers)

[
{
"Type": "volume"
"Name": "pgdata"
"Source": "/var/lib/docker/volumes/pgdata/_data"
"Destination": "/var/lib/postgresql/data"
"Driver": "local"
"RW": true
}
{
"Type": "bind"
"Source": "/srv/web"
"Destination": "/usr/share/nginx/html"
"Mode": "ro"
"RW": false
"Propagation": "rprivate"
}
]

Try it yourself

Mount one volume and one host directory and compare them in inspect.

$ docker volume create pgdata
$ sudo mkdir -p /srv/web && echo hello | sudo tee /srv/web/index.html
$ docker run -d --name web -v /srv/web:/usr/share/nginx/html:ro nginx
$ docker run -d --name db -e POSTGRES_PASSWORD=example -v pgdata:/var/lib/postgresql/data postgres:17
$ docker exec web touch /usr/share/nginx/html/x
$ docker inspect --format '{{json .Mounts}}' web db
$ docker rm -f web
$ docker rm -f db
$ docker volume rm pgdata

Quiz

1. Who manages a named volume's directory?
2. What happens to the image's files at a bind-mounted path?
3. What does :ro do?