← Knowledge Base
DockerReference note1 min read · updated 2026-11-27

Docker volumes versus bind mounts

Where container data should live, how to back up a named volume, and the permission pitfalls.

dockervolumesbackup
  • Named volume (appdata:/data): managed by Docker under /var/lib/docker/volumes/. Best for databases and app state.
  • Bind mount (./site:/usr/share/nginx/html:ro): a host folder, good for config and static files you edit directly. Add :ro when the container only reads.
docker volume ls
docker volume inspect appdata
# back up a named volume to a tarball
docker run --rm -v appdata:/data -v "$PWD":/backup alpine tar czf /backup/appdata.tgz -C /data .
# restore
docker run --rm -v appdata:/data -v "$PWD":/backup alpine tar xzf /backup/appdata.tgz -C /data

Permission problems usually mean the container user's UID differs from the host file owner. A bind mount pins the directory inode: if you replace the host directory (rename it, delete and recreate it), the container keeps seeing the old one until it is recreated (docker compose up -d --force-recreate).