This is a simple docker setup which can be used to quickly spin up a postgres instance populated with a existing db backup
and some extensions installed.
This is using the official Postgres 10.12 image in docker hub as the base image and it can be changed according the required version.
Only extra extension that is enabled on container start is PostGIS. This can also be customized by changing the POSTGRES_EXTENSION
variable in docker-compose
- You should have a database dump created using the
pg_dumptool to begin with. - Replace the dummy
db_backupfile in the backup folder with the actual backup. - Change the env variable
POSTGRES_DBin compose file to match the name of the database you are trying to restore. - Run
docker-compose buildto create the image with the backup and init files included. - Once the image is built, run
docker-compose up -dto start the new container using the image you just created.
You can use the same docker-compose.yml to spin up a clean postgres instance.
To do this just remove the env variable POSTGRES_DB from the compose file and run docker-compose up -d and it will use the postgres:10.12 from DockerHub to spin up the container.
Once the container is running you can connect to it using the credentials and ports configured in the compose file. By default it will use below values and you can easily change credentials by editing the compose file and changing the environment variables.
HOST: localhost
USER: postgres
PASSWORD: password