docker-compose: Fix Postgres volume mount#887
Conversation
https://github.com/docker-library/docs/blob/ea45618e3609152fb315e85c2ee8678e3a4a9324/postgres/README.md?plain=1#L216 > **Important Note:** (for PostgreSQL 17 and below) Mount the data volume at `/var/lib/postgresql/data` and not at `/var/lib/postgresql` because mounts at the latter path WILL NOT PERSIST database data when the container is re-created. The Dockerfile that builds the image declares a volume at `/var/lib/postgresql/data` and if no data volume is mounted at that path then the container runtime will automatically create an [anonymous volume](https://docs.docker.com/engine/storage/#volumes) that is not reused across container re-creations. Data will be written to the anonymous volume rather than your intended data volume and won't persist when the container is deleted and re-created.
SummaryChanges the PostgreSQL volume mount path in the docker-compose example from This is a critical fix for data persistence. When a volume is mounted at What reviewers should knowWhat to review:
Context for reviewers:
|
There was a problem hiding this comment.
The fix applied here is correct — mounting at /var/lib/postgresql/data is the right path for the PostgreSQL 17 image used in this compose file. However, the same silent data-loss bug exists in two other example files that this PR did not touch, leaving users of those examples exposed to the same problem.
Incomplete fix — same bug in other compose files:
-
example-compose-files/sq-dce-postgres/docker-compose.ymlline 150:postgresql:/var/lib/postgresql— identical to the bug fixed here; data will not persist across container re-creations for anyone using the DCE Postgres example. -
example-compose-files/sq-dce-custom-zip-postgres/docker-compose.ymllines 200–201: has both mounts —postgresql:/var/lib/postgresql(incorrect) andpostgresql_data:/var/lib/postgresql/data(correct). Data does survive here because the/datamount takes effect, but the parent-level mount is confusing dead weight and should be removed.tests/dce-compose-test/docker-compose.ymlhas the same two-mount pattern.
The PR should be expanded to fix sq-dce-postgres/docker-compose.yml at minimum. The sq-dce-custom-zip-postgres and tests/dce-compose-test files should have the redundant postgresql:/var/lib/postgresql line removed as well.
https://github.com/docker-library/docs/blob/ea45618e3609152fb315e85c2ee8678e3a4a9324/postgres/README.md?plain=1#L216
If you are frantically searching for your lost postgres data, look in /var/lib/docker/volumes for it:
Then copy the contents to the empty named volume: