简体   繁体   English

启动 postgres 容器时出错 - mkdir:权限被拒绝

[英]Error starting postgres container - mkdir: Permission denied

I am starting a postgres container using following docker-compose.yml我正在使用以下 docker-compose.yml 启动一个 postgres 容器

version: '3'
services:
  db:
    image: postgres:latest
    container_name: postgres
    environment:
      POSTGRES_USER: usr
      POSTGRES_PASSWORD: pswd
      POSTGRES_DB: db
      PGDATA: /var/lib/postgresql/data/pgdata
    ports:
        - 5432:5432
    volumes:
        - nfs_cur_dir:/var/lib/postgresql/data

volumes:
  nfs_cur_dir:
    driver: local
    driver_opts:
      type: nfs
      o: "addr=10.15.187.88,rw"
      device: ":/u/uname/home/database"

I am getting following error when starting the container启动容器时出现以下错误

$sudo ./docker-compose  up db
Starting postgres ... done
Attaching to postgres
postgres    | mkdir: cannot create directory ‘/var/lib/postgresql/data’: Permission denied
postgres exited with code 1

The permissions on database directory are 777 database目录的权限为 777

drwxrwxrwx 3 uname grpname 4096 May 5 22:57 database

After the failure I also see pgdata directory created as this -失败后,我还看到这样创建的pgdata目录 -

drwx------ 2 polkitd root 4096 May 5 22:57 pgdata

Note:笔记:

  • The data directory for the postgres is mapped to an NFS location. postgres 的数据目录映射到 NFS 位置。 Hence I have defined a new NFS volume in the docker-compose and mapped that to the postgres container.因此,我在 docker-compose 中定义了一个新的 NFS 卷,并将其映射到 postgres 容器。
  • I am using PGDATA env variable to define a different location for the data directory.我正在使用 PGDATA env 变量为数据目录定义不同的位置。
  • Other than above two things there is nothing out of ordinary.除了以上两点之外,没有什么不寻常的。 If I use a local drive location for the data directory this works fine !如果我对数据目录使用本地驱动器位置,则效果很好!

You should check the permissions that NFS share exposes.您应该检查 NFS 共享公开的权限。 According to what you said, if you use a local drive it works fine.根据您的说法,如果您使用本地驱动器,它可以正常工作。 That's why I think the NFS share's permissions aren't working as you expect.这就是为什么我认为 NFS 共享的权限没有按预期工作的原因。 Maybe you should create the directory before trying to run your application.也许您应该在尝试运行应用程序之前创建目录。

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

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