Docker setup for Postgres, TimescaleDB, and PostGIS

Set up a Postgres image with Timescale and PostGIS extensions, with a few functions for handling maintenance operations, borrowed from Cookiecutter Django.


Download the files in the git repository and run docker-compose

docker-compose build
docker-compose up -d

Test to confirm access and that our maintenance files were loaded correctly

docker-compose exec postgres backups
# These are the backups you have got:
# total 0      


The directory and file structure should look like the below:

├── Dockerfile
└── maintenance
    ├── backup
    ├── backups
    ├── restore
    └── _sourced


Additional information on these commands can be found here.

Create a backup

docker-compose exec postgres backup

List existing backups

docker-compose exec postgres backups

Copy backups locally

# Copy all files in the backups folder in Docker to a local folder "backups" in the current directory
docker cp <container-id>:/backups ./backups

# Copy a single file to the current directory "."
docker cp <container-id>:/backups/backup_<filename>.sql.gz .

Restore an existing backup

docker-compose exec postgres restore <filename>.sql.gz