Mysterious Docker issue with postgres

I’ve had this mysterious Docker error before error during container init: error mounting "/home/bla/Desktop/myproject/db/postgres-data" to rootfs at "/var/lib/postgresql/data": change mount propagation through procfd: open o_path procfd and I’ve scoured over the internet and have tried almost everything:

  1. Purged all the containers and images
  2. Restarted Docker
  3. Ran docker compose up -d --build and it’s again the same issue
  4. Attempted to run it both on Windows and Ubuntu it’s the same issue
  5. Added permissions to the entire repo in case that was the problem

Mysteriously enough on the server it works just fine, all I did was alter the db with a new column and delete the postgres-data folder and this error starting cropping up in my dev environment.

Has anyone ever had an issue with this, how did you overcome it?

2 Likes

In composse.yml I had postgres so it got the postgres latest. After changing it to postgres-16 it works. Where can I open an issue for this?

3 Likes

Probably in the official Docker Hub Postgres repo.

i have been looking all over the internet since GMT 10 am today
it was very frustrating, had tried so many different things, googling didn’t help, LLMs were not of help

Finally started googling each part of the error and found your solution, and it worked!
Thanks a lot!

From a comment on the Github issue:

—-

For version 18 the new data path is:
/var/lib/postgresql/18/docker

So the correct bind mount in command is:

docker run -d -v ~/test18:/var/lib/postgresql/18/docker -e POSTGRES_PASSWORD=test postgres:18

7 Likes

Works for me, thanks!

This image version worked for me.

i have alos encounter this issue but in docs
it says like this

Important Change: the PGDATA environment variable of the image was changed to be version specific in PostgreSQL 18 and above⁠. For 18 it is /var/lib/postgresql/18/docker. Later versions will replace 18 with their respective major version (e.g., /var/lib/postgresql/19/docker for PostgreSQL 19.x). The defined VOLUME was changed in 18 and above to /var/lib/postgresql. Mounts and volumes should be targeted at the updated location. This will allow users upgrading between PostgreSQL major releases to use the faster --link when running pg_upgrade and mounting /var/lib/postgresql.

Users who wish to opt-in to this change on older releases can do so by setting PGDATA explicitly (--env PGDATA=/var/lib/postgresql/17/docker --volume some-postgres:/var/lib/postgresql). To migrate pre-existing data, adjust the volume’s folder structure appropriately first (moving all database files into a PG_MAJOR/docker subdirectory).

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⁠ 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.

I hope this helps

It works for me. Thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.