Docker Volumes

Persist data with named volumes and bind mounts done right.

  • docker volume
  • bind mount
  • persist data
  • postgres docker
  • volume inspect

Docker Volumes

Persist data with named volumes and bind mounts done right.

Commands

CommandWhat it does
docker volume create pgdataCreate a named volume
docker volume lsList volumes
docker run -v pgdata:/var/lib/postgresql/data postgres:16Attach a volume
docker run -v $(pwd):/app -w /app node:22 npm run devBind-mount source for live dev
docker volume inspect pgdataSee where data lives on the host

Example

docker volume create pgdata
docker run -d --name pg -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=secret postgres:16

FAQ

Named volume vs bind mount?

Named volumes are portable and managed by Docker (best for databases); bind mounts mirror host source (best for dev).

Where is volume data on disk?

Under /var/lib/docker/volumes on Linux โ€” inspect it, but back it up via containers, not raw paths.

FAQ

Named volume vs bind mount?
Named volumes are portable and managed by Docker (best for databases); bind mounts mirror host source (best for dev).
Where is volume data on disk?
Under /var/lib/docker/volumes on Linux โ€” inspect it, but back it up via containers, not raw paths.

Docker