Docker无法识别Postgresql数据目录

Web*_*Dev 8 postgresql docker

我拼命想要获得一个我继承并运行的Docker项目,而Docker却没有给我带来任何问题.尝试启动我的容器时,我在Postgresql容器上收到以下错误:

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.
Run Code Online (Sandbox Code Playgroud)

该项目是一个使用Redis,ElasticSearch和Sidekiq容器的Rails项目 - 所有这些都很好.

泊坞窗,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
Run Code Online (Sandbox Code Playgroud)

/var/lib/postgresql/data 由postgres用户拥有(因为我应该相信)并且postgresql服务启动并且可以自行运行.

我试过initdb/usr/lib/postgresql/9.6/bin目录运行,以及从docker运行(从docker它似乎不会持续甚至创建任何东西......如果有人知道我为什么会有兴趣知道)

/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  
Run Code Online (Sandbox Code Playgroud)

PG_VERSION 包含9.6

任何帮助深表感谢.

cwu*_*rtz 1

因此,当有时postgres:/var/lib/postgresql/data,它将挂载/var/lib/postgresql/data到名为 的 docker 数据卷postgres。Docker 数据卷全部存储在一个位置,该位置因操作系统而异。

尝试将其更改为./postgres让它创建一个名为postgres相对于您的工作目录的目录。

由于源正在更改,它将重新创建数据库,并且我愿意修复您看到的错误。如果不是,则可能是主机操作系统上的权限问题。