A minimal Docker image combining PostgreSQL 18.4, PostGIS 3.6.4, and TimescaleDB 2.29.2, built on Alpine Linux 3.24.
| Component | Version |
|---|---|
| PostgreSQL | 18.4 |
| PostGIS | 3.6.4 |
| TimescaleDB | 2.29.2 |
| Alpine Linux | 3.24 |
docker run -d \
--name postgres \
-e POSTGRES_PASSWORD=yourpassword \
-e POSTGRES_DB=yourdb \
-e POSTGRES_USER=youruser \
-v pgdata:/var/lib/postgresql \
-p 5432:5432 \
ghcr.io/32u-nd/postgres-postgis-timescaledb:latestNote: The volume must be mounted to
/var/lib/postgresql(not/var/lib/postgresql/data). This is a breaking change introduced in PostgreSQL 18, wherePGDATAis now version-specific (/var/lib/postgresql/18/docker).
services:
db:
image: ghcr.io/32u-nd/postgres-postgis-timescaledb:latest
environment:
POSTGRES_PASSWORD: yourpassword
POSTGRES_DB: yourdb
POSTGRES_USER: youruser
volumes:
- pgdata:/var/lib/postgresql
ports:
- "5432:5432"
restart: unless-stopped
volumes:
pgdata:# PostGIS
docker exec -it postgres psql -U youruser -d yourdb \
-c "SELECT PostGIS_Full_Version();"
# TimescaleDB
docker exec -it postgres psql -U youruser -d yourdb \
-c "SELECT extversion FROM pg_extension WHERE extname = 'timescaledb';"On first start, init-db.sh is executed automatically and:
- Creates a
template_postgistemplate database - Enables
postgis,postgis_topology, andtimescaledbextensions in bothtemplate_postgisand$POSTGRES_DB
On subsequent starts with an existing volume, the script is skipped entirely by PostgreSQL.
All psql calls in init-db.sh connect explicitly via --dbname "$POSTGRES_DB".
Without it, psql connects to a database named after $POSTGRES_USER, which
never exists — only $POSTGRES_DB is created. On a non-empty volume this
script never runs, so the bug was invisible; it only surfaces on an empty
volume, which is exactly the disaster-recovery case.
All versions and checksums can be overridden at build time:
docker build \
--build-arg POSTGIS_VERSION=3.6.4 \
--build-arg POSTGIS_SHA256=<sha256> \
--build-arg TIMESCALEDB_VERSION=2.29.2 \
--build-arg TIMESCALEDB_SHA256=<sha256> \
-t my-postgres .Recalculate SHA256 checksums after a version change:
# PostGIS
curl -sL https://github.com/postgis/postgis/archive/refs/tags/<version>.tar.gz | sha256sum
# TimescaleDB
curl -sL https://github.com/timescale/timescaledb/archive/<version>.tar.gz | sha256sumSee UPDATE_CHECKLIST.md for a step-by-step guide on how to update PostgreSQL, PostGIS, or TimescaleDB to a newer version.
This repository (Dockerfile and scripts) is licensed under the MIT License.
The software included in the image is subject to its own licenses:
| Component | License |
|---|---|
| PostgreSQL | PostgreSQL License |
| PostGIS | GPL-2.0 |
| TimescaleDB | Timescale License — Community Edition is free; some enterprise features require a commercial license |
| Alpine Linux | Various |