Docker无法识别Postgresql数据目录 [英] Docker not recognizing Postgresql data directory

查看:544
本文介绍了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 initdb $ c>目录,以及来自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数据目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆