Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

628
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda