简体   繁体   English

initdb:无法更改 Postgresql 容器上目录的权限

[英]initdb: could not change permissions of directory on Postgresql container

I am new to the docker ecosystem and I am trying to spin up a simple postgres container along with a volume so it persists its data, by using a yaml composer file.我是 docker 生态系统的新手,我正在尝试使用 yaml composer 文件启动一个简单的 postgres 容器和一个卷,以便它保留其数据。 The file is as follows:该文件如下:

# Use postgres/example user/password credentials
version: '3.3'
services:
    db:
        image: postgres
        environment:
            POSTGRES_DB: recrow
            POSTGRES_USER: recrow
            POSTGRES_PASSWORD: recrow_db_1000
            PGDATA: /var/lib/pgsql/data/pgdata
        volumes:
          - ./pgsql/data:/var/lib/pgsql/data/pgdata

However, upon calling docker-compose -f stack.yml up I get the following error:但是,在调用docker-compose -f stack.yml up ,出现以下错误:

fixing permissions on existing directory /var/lib/postgresql/data/pgdata ... initdb: could not change permissions of directory "/var/lib/postgresql/data/pgdata": Operation not permitted修复现有目录 /var/lib/postgresql/data/pgdata 的权限... initdb:无法更改目录“/var/lib/postgresql/data/pgdata”的权限:不允许操作

/var/lib/pgsql/data/pgdata is supposed to be a directory relative to the container's root, while ./pgsql/data is a path on the host. /var/lib/pgsql/data/pgdata应该是相对于容器根目录的目录,而./pgsql/data是主机上的路径。 I am running the container from an ntfs-3g partition mounted on /mnt/storage .我正在从/mnt/storage上安装的 ntfs-3g 分区运行容器。 What could be the problem?可能是什么问题? I am also running docker without root permissions, by adding my user to the docker group and this user also has full access to the beforementioned mount point /mnt/storage .我也在没有 root 权限的情况下运行 docker,将我的用户添加到 docker 组,并且该用户还可以完全访问上述挂载点/mnt/storage

I'm guessing this is going to be an incompatibility with ntfs-3g.我猜这将与 ntfs-3g 不兼容。 The PostgreSQL image contains an entrypoint script that is doing some permission changes on container start: https://github.com/docker-library/postgres/blob/972294a377463156c8d61297320c872fc7d370a9/9.6/docker-entrypoint.sh#L32-L38 . PostgreSQL 映像包含一个入口点脚本,该脚本在容器启动时进行一些权限更改: https : //github.com/docker-library/postgres/blob/972294a377463156c8d61297320c872fc7d370a9/9.6/docker-entrypoint.sh#L32-L38 I found another relevant question at https://askubuntu.com/questions/11840/how-do-i-use-chmod-on-an-ntfs-or-fat32-partition that talks about being able to set permissions at mount time.我在https://askubuntu.com/questions/11840/how-do-i-use-chmod-on-an-ntfs-or-fat32-partition发现了另一个相关问题,该问题讨论了能够在挂载时设置权限. But not being able to change via chmod or chown (which is likely the reason for the failure in this case).但是无法通过chmodchown进行更改(这可能是这种情况下失败的原因)。

Unfortunately, I think the answer here is that you cannot use ntfs-3g safely for backing Docker host volume mounts.不幸的是,我认为这里的答案是您不能安全地使用 ntfs-3g 来支持 Docker 主机卷安装。

Following off of @liam-mitchell's note above, that is the answer.按照上面@liam-mitchell 的注释,这就是答案。 Use named volumes such like the following:使用如下命名的卷:

services:
  db:
    image: postgres:12-alpine
    volumes:
      - "postgres:/data/postgres"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - PGDATA=/data/postgres

...

volumes:
  postgres:

I work with OpenShift and had the same problem to run this official image from Docker Hub.我使用 OpenShift 并且在从 Docker Hub 运行这个官方镜像时遇到了同样的问题。

In my case, the solution was to use the official postgres image from red hat repository, the image from red hat repository has fixed this problem, this is can be an alternative.就我而言,解决方案是使用来自 red hat 存储库的官方 postgres 图像,来自 red hat 存储库的图像已解决此问题,这可以作为替代方案。

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

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