PostgreSQL具有Docker所有权问题 [英] PostgreSQL with docker ownership issue
问题描述
从昨天开始,我尝试在Windows(Bootcamp MacBook Pro)上启动docker项目,而我只剩下一个问题:PostgreSQL映像.
Since yesterday, I try to launch my docker project on Windows (Bootcamp MacBook Pro), and I have just one issue left : PostgreSQL image.
错误消息:
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
我到处搜索,尝试了所有内容,但仍然遇到这个问题……
I've searched everywhere, tried everything, and still have this issue…
我尝试的是:
- 使用
docker volume create --name postgres -d local
创建Docker卷并在我的docker-compose.yml中使用它
- Create docker volume with
docker volume create --name postgres -d local
and use it in my docker-compose.yml
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,数据…)声明多个卷
我试图docker整理,重新启动计算机,删除图像,没有任何变化,相同的错误.
I tried to docker compose down, restart computer, remove images, nothing change, same error.
我已经在Docker Settings中选中了Shared Drive框.
I already checked Shared Drive box in Docker Settings.
我尝试过的来源:
https://glennsarti.github.io/blog/puppet-in-docker/
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
有人可以作为工作解决方案吗?我将继续使其工作,并在发现某事后更新帖子.
Is anyone as a working solution ? I will continue to make it work, and update post if I found Something.
谢谢.
推荐答案
我终于弄清楚了我尝试将卷用于PostgreSQL数据时出了什么问题.
I've finally figured out what went wrong when I tried to use a volume for PostgreSQL data.
我不知道我们使用了 docker-compose.override.yml
,该声明使用Windows路径声明了一个卷.
I had no idea that we used a docker-compose.override.yml
, which declare a volume with a Windows path.
因此,这是一个在Windows的Docker上安装PostgreSQL并具有持久数据的可行解决方案:
So here is a working solution to have PostgreSQL on Docker for Windows, with persisted data :
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
(无需其他命令)
这篇关于PostgreSQL具有Docker所有权问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!