- 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:rowhen 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).