PostgreSQL具有Docker所有权问题

Azu*_*ken 5 postgresql docker docker-compose

从昨天开始,我尝试在Windows(Bootcamp MacBook Pro)上启动docker项目,而我只剩下一个问题:PostgreSQL映像。

错误信息 :

postgres_1         | The files belonging to this database system will be owned by user "postgres".
postgres_1         | This user must also own the server process.
postgres_1         |
postgres_1         | The database cluster will be initialized with locale "en_US.utf8".
postgres_1         | The default database encoding has accordingly been set to "UTF8".
postgres_1         | The default text search configuration will be set to "english".
postgres_1         |
postgres_1         | Data page checksums are disabled.
postgres_1         |
postgres_1         | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres_1         | creating subdirectories ... ok
postgres_1         | selecting default max_connections ... 20
postgres_1         | selecting default shared_buffers ... 400kB
postgres_1         | selecting dynamic shared memory implementation ... posix
postgres_1         | creating configuration files ... ok
postgres_1         | 2019-01-22 16:57:37.016 UTC [79] FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
postgres_1         | 2019-01-22 16:57:37.016 UTC [79] HINT:  The server must be started by the user that owns the data directory.
postgres_1         | child process exited with exit code 1
postgres_1         | initdb: removing contents of data directory "/var/lib/postgresql/data"
postgres_1         | running bootstrap script ... kibati-docker_postgres_1 exited with code 1
Run Code Online (Sandbox Code Playgroud)

我到处搜索,尝试了所有内容,但仍然遇到这个问题……

我试过的是:

  • 使用创建docker卷docker volume create --name postgres -d local并在我的docker-compose.yml中使用它

docker-compose.yml

version: '2'

services:
  postgres:
    image: postgres:latest
    ports:
      - "5432:5432"
    volumes:
      - postgres:/var/lib/postgresql/data

  networks:
    internal_ip:
      ipv4_address: 192.168.1.2

  volumes:
    postgres:
      external: true
Run Code Online (Sandbox Code Playgroud)
  • 直接在Docker中添加卷

体积样本

volumes:
  postgres:
    driver: local
Run Code Online (Sandbox Code Playgroud)
  • 使用相对或绝对Windows路径
  • 为不同的PostgreSQL文件夹声明多个卷(conf,data…)

我试图docker撰写下来,重新启动计算机,删除图像,没有任何变化,同样的错误。

我已经在Docker Settings中选中了Shared Drive框。

我尝试过的来源:

https://glennsarti.github.io/blog/puppet-in-docker/

https://forums.docker.com/t/trying-to-get-postgres-to-work-on-persistent-windows-mount-two-issues/12456/5

https://forums.docker.com/t/data-directory-var-lib-postgresql-data-pgdata-has-wrong-ownership/17963/28

https://github.com/docker-library/postgres/issues/435

http://www.lukaszewczak.com/2016/09/run-postgresql-using-docker-with.html

https://gdevops.gitlab.io/tuto_docker/tutoriels/postgresql/postgresql.html

https://devask.cz/questions/48645804/mount-postgres-data-to-windows-host-directory

有谁可以作为工作解决方案?我将继续使其工作,并在发现某些内容后更新帖子。

提前致谢。

Azu*_*ken 8

当我尝试将卷用于 PostgreSQL 数据时,我终于弄清楚出了什么问题。

我不知道我们使用了 a docker-compose.override.yml,它声明了一个带有 Windows 路径的卷。

所以这是一个在 Docker for Windows 上使用 PostgreSQL 的有效解决方案,具有持久化数据:

version: '2'

services:
  postgres:
    image: postgres:11.5
    ports:
      - 5432:5432
    volumes: 
      - pgdata:/var/lib/postgresql/data
      - pgconf:/etc/postgresql
      - pglog:/var/log/postgresql

volumes:
  pgdata:
    driver: local
  pgconf:
    driver: local
  pglog: 
    driver: local
Run Code Online (Sandbox Code Playgroud)

(不需要额外的命令)