Docker-Compose Postgresql导入转储

Sim*_*mon 11 postgresql docker docker-compose

我有关于docker和postgres的问题.每次docker启动时我都要设置一个新的postgres数据库并想要导入给定的转储.

我的问题就像,但答案对我来说还不够:Docker postgres不会在docker-entrypoint-initdb.d中运行init文件

多克尔 - 撰写:

postgres:
  environment:
   - POSTGRES_USER=****
   - POSTGRES_PASSWORD=****
   - POSTGRES_DB=****
build:
  context: .
  dockerfile: dockerfile-postgres
Run Code Online (Sandbox Code Playgroud)

我的Dockerfile :(我已经尝试使用.sh结尾的脚本)

FROM postgres
ADD dump.sql /docker-entrypoint-initdb.d/
Run Code Online (Sandbox Code Playgroud)

根据https://hub.docker.com/_/postgres/ dump.sql必须用于导入数据库.

使用docker启动应用程序只会给出:

postgres_1     | LOG:  invalid record length at 0/1708600
postgres_1     | LOG:  redo is not required
postgres_1     | LOG:  MultiXact member wraparound protections are now enabled
postgres_1     | LOG:  database system is ready to accept connections
postgres_1     | LOG:  autovacuum launcher started
Run Code Online (Sandbox Code Playgroud)

除了我测试我的数据库是否已导入,我的数据库中没有表.我做错了什么(文件在目标系统上读取和执行)?用psql导入它没问题,所以我的转储是正确的.

我希望你能帮助我,我想提前感谢你.

Sim*_*mon 14

好吧,我找到了诀窍,我必须执行"docker-compose rm"才能执行此文件夹中的脚本和sql文件.一旦构建并且未被删除,则忽略init文件夹.

更新 我再次遇到这个问题,这次删除图像docker创建解决了问题.