简体   繁体   中英

Bluemix postgres container with volume attached, failed with 'permission error'

I have postgres docker image, which can be deployed on Bluemix Containers. It works fine. But when I attached volume, container fails with permission error.

I am using $PGDATA as /var/lib/postgresql/data. Entry point script, I have mentioned, sudo chown -R postgres /var/lib/postgresql/data. Also I have mounted volume using option -v data1:/var/lib/postgresql/data

But when I start container, chown always fails with 'Permission Error'.

I have added postgres user as part of root group. But it still gives me same error.

chown: changing ownership of ?/var/lib/postgresql/data?: Permission denied

How do I fix this issue?

I found a way arround adding postgress to root group (which is a security flaw in my eyes).

At first you make the volume writable for everyone, then add an folder in the volume with the user you want to run your daemon with (in your case postgres). After this you can reset the volumes access right to default again.

I use this snippet in my entrypoint scripts on setup time:

chsh -s /bin/bash www-data
chmod 777 /var/www
su -c "mkdir -p /var/www/html" www-data
chmod 755 /var/www
usermod -s /bin/false www-data

Instead of chown volume directory to postgres user, change its permission to allow group write:

$ chmod g+w $PGDATA

Since you already added root group to user postgres it should work now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM