Docker Community Forums

Share and learn in the Docker community.

Initialize Postgres Image with backup files from pg_basebackup

I am running into a problem with the Docker Postgres image. Here is what I am doing:

1. Create Docker Postgres Image with my own Dockerfile using "FROM postgres:13.4", I basically have some files I copy over to initialize the DB and set the runtime configurations.  Also, I have a script to run pg_basebackup.
2. Create a Container from the Image above.
3. After Container is created and Postgres is up and running, I run my pg_basebackup script to obtain the backup files from the Master Host.
4. To restore the Slave, I need to first stop the Postgres server.

This is where my problems is. When I shut down Postgres, it closes the Container.

Is it possible to stop the Postgres server without stopping the Container?
– OR –
Can I copy over the backup files while Postgres is executing, and then restart the container to pick up the changes?