PostgreSQL · infra · fg-0276

postgres:18 container fails to start or loses data when the volume is mounted at /var/lib/postgresql/data

If you see error mounting "..." to rootfs at "/var/lib/postgresql/data": ... no such file or directory: unknown, the cause and the fix for PostgreSQL are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
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

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun