简体   繁体   English

带有卷的Bluemix postgres容器,失败,出现“权限错误”

[英]Bluemix postgres container with volume attached, failed with 'permission error'

I have postgres docker image, which can be deployed on Bluemix Containers. 我有postgres docker映像,该映像可以部署在Bluemix Containers上。 It works fine. 工作正常。 But when I attached volume, container fails with permission error. 但是,当我附加卷时,容器将失败,并显示权限错误。

I am using $PGDATA as /var/lib/postgresql/data. 我正在使用$ PGDATA作为/ var / lib / postgresql / data。 Entry point script, I have mentioned, sudo chown -R postgres /var/lib/postgresql/data. 我已经提到入口点脚本,sudo chown -R postgres / var / lib / postgresql / data。 Also I have mounted volume using option -v data1:/var/lib/postgresql/data 另外我已经使用选项-v data1挂载了卷:/ var / lib / postgresql / data

But when I start container, chown always fails with 'Permission Error'. 但是,当我启动容器时,chown总是失败,并显示“权限错误”。

I have added postgres user as part of root group. 我已将postgres用户添加为根组的一部分。 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). 我找到了一种在根组中添加postgress的方法(在我看来这是一个安全缺陷)。

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). 首先,使该卷对所有人都可写,然后在该卷中添加一个您要与之一起运行守护程序的用户的文件夹(在您的情况下为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: 更改其权限以允许组写入,而不是为postgres用户添加chown卷目录:

$ chmod g+w $PGDATA

Since you already added root group to user postgres it should work now. 由于您已经将root组添加到用户postgres ,因此现在应该可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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