与docker的Postgres失去连接,并获得文件系统的问题

我正在使用Docker 17.06.0Docker 17.06.0 docker-compose 1.14.0来使用Postgres 9.4.1 。 当我使用它的时候,经常会发生连接丢失的情况,在日志中我得到这个:

 LOG: invalid length of startup packet LOG: could not send data to client: Broken pipe FATAL: connection to client lost ERROR: could not open file "base/1/11943": No such file or directory FATAL: could not open file "base/12141/11943": No such file or directory 

重新启动容器后,它没有得到任何改善:

 postgres cannot access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory 

我唯一的解决办法是:

  1. 停止容器并将其移除
  2. 删除卷的所有数据
  3. 重新启动泊坞窗
  4. 容器。

说实话,这是相当烦人的过程。 它总是发生在我断开当前的networking,有时只是当我使用postgres。 也许我错过了一些权限configuration,这是我docker-compose.yml

 postgres: image: postgres:9.4.1 ports: - 54320:54320 environment: - POSTGRES_USER=xxx - POSTGRES_PASSWORD=xxx volumes: - /tmp/postgres/staging:/var/lib/postgresql/data restart: always