A Docker volume provides host-managed persistence for container data. Mounting postgres-volume at /var/lib/postgresql/data keeps PostgreSQL files available after stopping, removing, or recreating the container. section 1.3
Persist PostgreSQL data
Create and mount a volume with: docker volume create postgres-volume, then docker run --name postgres -v postgres-volume:/var/lib/postgresql/data -d postgres:17.2. The container runs PostgreSQL in the background while Docker stores its database files on the host. section 1.3
Listing 1.1 Starting a Postgres container on Unix
docker volume create postgres-volume
docker run --name postgres \
-e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password \
-p 5432:5432 \
-v postgres-volume:/var/lib/postgresql/data \
-d postgres:17.2
Use the Unix command listing to create postgres-volume and mount it into the PostgreSQL data directory. section 1.3







