docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.17k stars 1.13k forks source link

Postgres container fails to start due to permissions issue #1213

Closed achint740 closed 6 months ago

achint740 commented 6 months ago

Hello everyone,

I know this issue FATAL: data directory "/var/lib/postgresql/data" has wrong ownership has been discussed a lot of times. I've gone through a lot of such issues and tried to fix it at my end, but none has been helpful. I will list down more details below.

I am using this docker image : postgres:12.5-alpine. I have a NFS mount like /<nfs_mount_name>/postgres/data. Earlier my deployment was using docker-compose through the root user but recently I am trying to shift to using podman.

The NFS mount has permissions drwxr-xr-x with the owner being, say user 'A' and group 'B'. Now, I try to run a container using podman run --user <uid_of_user_A>:<gid_of_user_B> -v <my_nfs_mount>:/var/lib/postgresql/data --env-file .env.pg postgres:12.5-alpine The .env.pg contains POSTGRES_USER and POSTGRES_PASSWORD.

The detailed error look like :

chmod: /var/lib/postgresql/data: Operation not permitted
chmod: /var/run/postgresql: Operation not permitted

PostgreSQL Database directory appears to contain a database; Skipping initialization

 FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
 HINT:  The server must be started by the user that owns the data directory.

Let me know for any additonal information required. Any help would be much appreciated! Thanks

achint740 commented 6 months ago

@yosifkit if you might have more context and can help here? Sorry for tagging, but I noticed your solutions in a couple of similar cases to be useful. Thanks