Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

622
Views
how to restore postgres database in docker when docker container not start?

I want to create a database in PostgreSQL and restore a backup in a docker container. I am able to create the database and run the docker container, and then run the pg_restore to restore the backup. My Dockerfile is :

FROM postgres:latest

ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD 123qwe 
ENV POSTGRES_DB docker_pg 

COPY createTable.sql /docker-entrypoint-initdb.d/

VOLUME /var/lib/postgresql/data

Then I run the command for restore the backup :

docker exec -i 0d96d6b59d74 pg_restore -U postgres -d docker_pg< backup_latest.sql

It is working fine.

But my requirement is when I run the command for create the docker container database creation and restore the backup both work done in same time, mean at the time of container creation.

How can I do this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

But my requirement is when I run the command for create the docker container database creation and restore the backup both work done in same time, mean at the time of container creation.

Both tasks can be performed by the Docker container all you need to place the restore script in the docker-entrypoint-initdb.d folder.

COPY createTable.sql /docker-entrypoint-initdb.d/a_createTable.sql
COPY backup_latest.sql /docker-entrypoint-initdb.d/

As I changed createTable.sql to a_createTable.sql, so it will first create Table and then it will restore the backup.

These initialization files will be executed in sorted name order as defined by the current locale

Initialization scripts

Or the other option is to create single SQL file and the order will be

ALL DDL 
# then 
ALL DML

so something like

COPY db.sql /docker-entrypoint-initdb.d/

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!