Skip to content

Latest commit

 

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostgreSQL + PostGIS + TimescaleDB on Alpine

A minimal Docker image combining PostgreSQL 18.4, PostGIS 3.6.4, and TimescaleDB 2.29.2, built on Alpine Linux 3.24.

Build and Push Docker Image Platforms License

Included Versions

Component Version
PostgreSQL 18.4
PostGIS 3.6.4
TimescaleDB 2.29.2
Alpine Linux 3.24

Quick Start

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:latest

Note: The volume must be mounted to /var/lib/postgresql (not /var/lib/postgresql/data). This is a breaking change introduced in PostgreSQL 18, where PGDATA is now version-specific (/var/lib/postgresql/18/docker).

Docker Compose

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:

Verify Extensions

# 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';"

Initialization

On first start, init-db.sh is executed automatically and:

  • Creates a template_postgis template database
  • Enables postgis, postgis_topology, and timescaledb extensions in both template_postgis and $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.

Build Arguments

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 | sha256sum

Updating Versions

See UPDATE_CHECKLIST.md for a step-by-step guide on how to update PostgreSQL, PostGIS, or TimescaleDB to a newer version.

Licenses

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

About

Docker image PostgreSQL + PostGIS + TimescaleDB on Alpine, build for amd64 and arm64

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages