Docker无法识别Postgresql数据目录

编程入门 行业动态 更新时间:2024-10-27 00:29:49
本文介绍了Docker无法识别Postgresql数据目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我拼命地尝试让我继承并运行的Docker项目开始运行,而Docker却给我带来了无尽的麻烦。尝试启动容器时,我在Postgresql容器上收到以下错误:

I am desperately trying to get a Docker project I have inherited up and running, and Docker is giving me no end of problems. When trying to start up my containers I get the following error on my Postgresql container:

FATAL: "/var/lib/postgresql/data" is not a valid data directory DETAIL: File "/var/lib/postgresql/data/PG_VERSION" does not contain valid data. HINT: You might need to initdb.

该项目也是使用Redis,ElasticSearch和Sidekiq容器的Rails项目-所有这些都可以正常加载

The project is a Rails project using Redis, ElasticSearch, and Sidekiq containers as well - those all load fine.

docker-compose.yml:

docker-compose.yml:

postgres: image: postgres:9.6.2 environment: POSTGRES_USER: $PG_USER POSTGRES_PASSWORD: $PG_PASS ports: - '5432:5432' volumes: - postgres:/var/lib/postgresql/data

/ var / lib / postgresql / data 由postgres用户拥有(应该相信),并且postgresql服务可以启动并可以正常运行。

/var/lib/postgresql/data is owned by the postgres user (as it should be I believe) and the postgresql service starts up and runs fine on its own.

我尝试从 /usr/lib/postgresql/9.6/bin 目录,以及来自docker的目录(从docker似乎都不会持久,甚至不会创建任何东西……如果有人知道为什么我会对知道的东西感兴趣)

I have tried running initdb from the /usr/lib/postgresql/9.6/bin directory, as well as from docker (from docker it doesn't seem to persist or even create anything... if anyone knows why I would be interested in knowing)

/ var / lib / postgresql / data 目录的内容:

drwxrwxrwx 19 postgres postgres 4096 Jun 28 20:41 . drwxr-xr-x 5 postgres postgres 4096 Jun 28 20:41 .. drwx------ 5 postgres postgres 4096 Jun 28 20:41 base drwx------ 2 postgres postgres 4096 Jun 28 20:41 global drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_clog drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_commit_ts drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_dynshmem -rw------- 1 postgres postgres 4468 Jun 28 20:41 pg_hba.conf -rw------- 1 postgres postgres 1636 Jun 28 20:41 pg_ident.conf drwx------ 4 postgres postgres 4096 Jun 28 20:41 pg_logical drwx------ 4 postgres postgres 4096 Jun 28 20:41 pg_multixact drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_notify drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_replslot drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_serial drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_snapshots drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_stat drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_stat_tmp drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_subtrans drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_tblspc drwx------ 2 postgres postgres 4096 Jun 28 20:41 pg_twophase -rw------- 1 postgres postgres 4 Jun 28 20:41 PG_VERSION drwx------ 3 postgres postgres 4096 Jun 28 20:41 pg_xlog -rw------- 1 postgres postgres 88 Jun 28 20:41 postgresql.auto.conf -rw------- 1 postgres postgres 22267 Jun 28 20:41 postgresql.conf

PG_VERSION 包含9.6

我们非常感谢您的帮助。

Any help is much appreciated.

推荐答案

您正在更改默认的postgresql数据路径,因此需要初始化数据库。试试这个

you're changing default postgresql data path hence you need to initialize the database. try this

volumes: - ./init.sql:/docker-entrypoint-initdb.d/init.sql

这是init.sql文件

here is the init.sql file

CREATE USER docker; CREATE DATABASE docker; GRANT ALL PRIVILEGES ON DATABASE docker TO docker;

更多推荐

Docker无法识别Postgresql数据目录

本文发布于:2023-10-23 06:17:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520039.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法识别   目录   数据   Docker   Postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!