- Symptom
- error mounting "..." to rootfs at "/var/lib/postgresql/data": ... no such file or directory: unknownThe database is empty after the container is recreated even though a volume was mounted
- Cause
- From PostgreSQL 18 the official image sets PGDATA to /var/lib/postgresql/18/docker and declares the volume at /var/lib/postgresql, so a mount at the old data path is not where the server writes.
- Fix
- Mount the volume at /var/lib/postgresql for 18 and later. For existing data, move the files into an 18/docker subfolder after a proper upgrade, or keep the 17 tag until then.
- Apply
services: db: image: postgres:18 volumes: - pgdata:/var/lib/postgresql- Affected
- Docker Official Image postgres 18 and later (September 2025)
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders