【问题标题】:Bluemix postgres container with volume attached, failed with 'permission error'附加了卷的 Bluemix postgres 容器,因“权限错误”而失败
【发布时间】:2016-03-03 04:39:02
【问题描述】:

我有 postgres docker 镜像,可以部署在 Bluemix Containers 上。它工作正常。但是当我附加卷时,容器失败并出现权限错误。

我使用 $PGDATA 作为 /var/lib/postgresql/data。 入口点脚本,我已经提到过,sudo chown -R postgres /var/lib/postgresql/data。我还使用选项 -v data1:/var/lib/postgresql/data 安装了卷

但是当我启动容器时,chown 总是会因为“权限错误”而失败。

我已将 postgres 用户添加为 root 组的一部分。 但它仍然给我同样的错误。

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

我该如何解决这个问题?

【问题讨论】:

  • 所有这些文件的所有者,为什么所有者还不是“postgres”?
  • 由于这是附加到容器的卷上,所有权是 root。这就是原因,我正在尝试将所有权更改为 postgres。

标签: postgresql containers ibm-cloud


【解决方案1】:

我找到了一种将 postgress 添加到根组的方法(这在我看来是一个安全漏洞)。

首先,您使卷对所有人都可写,然后在卷中添加一个文件夹,其中包含您要运行守护程序的用户(在您的情况下为 postgres)。在此之后,您可以再次将卷访问权限重置为默认值。

我在设置时在我的入口点脚本中使用了这个 sn-p:

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

【讨论】:

    【解决方案2】:

    chown 卷目录替换为postgres 用户,将其权限更改为允许组写入:

    $ chmod g+w $PGDATA
    

    由于您已经将root 组添加到用户postgres,它现在应该可以工作了。

    【讨论】:

      猜你喜欢
      • 2018-09-08
      • 1970-01-01
      • 2016-05-18
      • 2019-01-18
      • 2011-04-12
      • 2017-08-31
      • 1970-01-01
      • 2018-10-28
      • 1970-01-01
      相关资源
      最近更新 更多