gpt4 book ai didi

具有 docker 所有权问题的 PostgreSQL

转载 作者:行者123 更新时间:2023-11-29 11:28:45 35 4
gpt4 key购买 nike

从昨天开始,我尝试在 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

我到处搜索,尝试了一切,仍然有这个问题......

我试过的是:

  • 使用 docker volume create --name postgres -d local 创建 docker volume 并在我的 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
  • 直接在 docker compose 中添加卷

体积样本

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

我尝试 docker compose down,重启电脑,删除图像,没有任何变化,同样的错误。

我已经在 Docker 设置中选中了共享驱动器框。

我尝试过的来源:

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

有没有人是可行的解决方案?我会继续让它发挥作用,如果我发现了什么,我会更新帖子。

提前致谢。

最佳答案

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

我不知道我们使用了 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

(不需要额外的命令)

关于具有 docker 所有权问题的 PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54323348/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com