泊坞窗无法还原Postgres备份

时间:2019-01-23 13:22:44

标签: postgresql docker

我正在尝试使用docker创建和还原postgres备份。 码头工人做不到,给了我以下错误:

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

dockerfile:

FROM postgres:11

ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD postgres
ENV POSTGRES_DB dbName

COPY backup.backup /
COPY initdb.sh /docker-entrypoint-initdb.d

initdb.sh:

pg_restore --username=postgres --create --exit-on-error --verbose --dbname=dbName backup.backup

docker-compose.yml:

version: '2'

services:
  db:
image: postgres:11
expose:
  - "5432"
ports:
  - "15432:5432"
volumes:
  - dock-volume:/var/lib/postgresql/data
environment:
  - POSTGRES_PASSWORD= postgres
  - POSTGRES_DB= dbName


volumes:
  dock-volume:

我试图将环境变量添加到docker-compose.yml中,但这无济于事。

1 个答案:

答案 0 :(得分:0)

您不应为Postgres创建# leave this one out of the try block - # there's nothing you can do here about a connection error # so let the calling code deal with it self.connect() try: self.cursor.execute(sql, params) except Exception as e: self.connection.rollback() finally: # this will ALWAYS be executed (unless `self.connect()` raised # but then you don't even want to close the connection <g> self.close() ,因为您的Dockerfile文件中已有定义。您在Dockercompose下定义的变量在Postgres内部可见。如果要备份并确保在初始化时正在运行,可以执行以下操作:

environment

然后Postgres初始化此脚本时将运行。您可以在volumes: - ~/Downloads/data/my_buckup.psql:/docker-entrypoint-initdb.d/stage.sql

部分下查看文档here

我希望这是有道理的