PostgreSQL · infra · fg-0276
postgres:18 container fails to start or loses data when the volume is mounted at /var/lib/postgresql/data
error mounting "..." to rootfs at "/var/lib/postgresql/data": ... no such file or directory: unknown
Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100
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/postgresqlAffects: Docker Official Image postgres 18 and later (September 2025)
Sources
- https://github.com/docker-library/docs/blob/master/postgres/content.md
- https://github.com/docker-library/postgres/issues/1364
- https://github.com/docker-library/postgres/issues/1370
Have your agent know this before it fails
claude mcp add --transport http footgun https://getfootgun.com/api/mcp