Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-Compose Postgresql import dump

I have a question about docker and postgres. I am setting up a new postgres database every time docker is starting up and want to import a given dump.

My Problem is like, but the answers are not sufficient for me: Docker postgres does not run init file in docker-entrypoint-initdb.d

Docker-Compose:

postgres:
  environment:
   - POSTGRES_USER=****
   - POSTGRES_PASSWORD=****
   - POSTGRES_DB=****
build:
  context: .
  dockerfile: dockerfile-postgres

My Dockerfile: (I tried it already with a script with .sh ending)

FROM postgres
ADD dump.sql /docker-entrypoint-initdb.d/

According to https://hub.docker.com/_/postgres/ dump.sql must be used to import the database.

Starting up the application with docker only gives:

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

Besides I tested if my database has been imported, there is no table in my database. What am I doing wrong (files are read- and executable on target system)? Importing it with psql is no problem, so my dump is correct.

I hope you can help me and I want to thank you in advance for it.

like image 573
Simon Avatar asked Jun 15 '16 11:06

Simon


1 Answers

Okay I found the trick, I have to execute "docker-compose rm" in order to execute the scripts and sql files within this folder. Once built and not removed the init folder is being ignored.

UPDATE I ran into this problem again, this time removing the images docker created resolved the problem.

like image 140
Simon Avatar answered Oct 29 '22 09:10

Simon