A lightweight, performance-optimized PostgreSQL image with PostGIS spatial extensions. Built on Alpine Linux for minimal size while maintaining full spatial database functionality.
- 🗜️ Lean Build: ~329MB image size (vs 600MB+ for standard PostGIS)
- 🚀 Performance Focused: Optimized for speed and resource efficiency
- 🧩 Core PostGIS: Full support for geometry types and spatial functions
- 🔄 Multi-Architecture: Native support for both ARM64 and AMD64 platforms
- 🧪 Thoroughly Tested: Comprehensive test suite ensures reliability
- 🔒 Secure Base: Built on official PostgreSQL Alpine images
- 📦 Latest Versions: PostgreSQL 18 + PostGIS 3.6.2
- ✅ Core PostGIS spatial types and functions
- ✅ GEOS geometry engine
- ✅ PROJ coordinate transformation library
- ✅ Spatial indexing (GIST)
- ✅ Spatial relationships (contains, within, etc.)
- ✅ Distance calculations
- ✅ Coordinate transformations
- ❌ Raster support
- ❌ Topology extension
- ❌ Tiger geocoder
- ❌ GUI tools
# Pull the image
docker pull ghcr.io/clevercactus-dev/docker-lean-postgis:latest
# Run a container
docker run -d \
--name postgis \
-e POSTGRES_PASSWORD=mysecretpassword \
-e POSTGRES_DB=mydb \
-p 5432:5432 \
ghcr.io/clevercactus-dev/docker-lean-postgis:latestThe following tagging scheme is used for this image:
| Tag | Description |
|---|---|
latest |
Latest stable build from the main branch |
RELEASE.YYYY-MM-DDTHH-mm-ssZ |
Timestamped release builds from main branch |
main-sha |
Specific commit from main branch |
branch-YYYY-MM-DDTHH-mm-ssZ |
Timestamped builds from other branches |
branch-sha |
Specific commit from other branches |
All images are multi-architecture and will automatically use the appropriate version for your platform (AMD64 or ARM64).
| Variable | Description | Default |
|---|---|---|
POSTGRES_PASSWORD |
PostgreSQL password (required) | - |
POSTGRES_USER |
PostgreSQL username | postgres |
POSTGRES_DB |
Database name | postgres |
PGDATA |
Data directory | /var/lib/postgresql/18/docker |
All standard PostgreSQL environment variables are supported. See the official PostgreSQL Docker documentation for more details.
Note: Starting with PostgreSQL 18, the PGDATA path is now version-specific to enable easier major version upgrades using
pg_upgrade --link.
services:
postgis:
image: ghcr.io/clevercactus-dev/docker-lean-postgis:latest
environment:
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_DB: mydb
ports:
- "5432:5432"
volumes:
- postgis-data:/var/lib/postgresql
volumes:
postgis-data:PostgreSQL 18 introduces a breaking change in the data directory structure. If you're upgrading from a previous version of this image (PostgreSQL 17), you have two options:
Keep using your existing volumes by explicitly setting the PGDATA environment variable:
services:
postgis:
image: ghcr.io/clevercactus-dev/docker-lean-postgis:latest
environment:
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_DB: mydb
PGDATA: /var/lib/postgresql/data # Use old location
ports:
- "5432:5432"
volumes:
- postgis-data:/var/lib/postgresql/data # Old mount point
volumes:
postgis-data:For new deployments or when you want to benefit from easier future upgrades:
-
Backup your existing data:
docker exec your-container pg_dumpall -U postgres > backup.sql
-
Update your docker-compose.yml to use the new volume mount:
volumes: - postgis-data:/var/lib/postgresql # New mount point
-
Start the new container and restore:
docker-compose up -d docker exec -i your-container psql -U postgres < backup.sql
Why this change? The new versioned PGDATA path (
/var/lib/postgresql/18/docker) enables faster major version upgrades usingpg_upgrade --linkby keeping data directories separate per version.
To build the image locally:
# Clone the repository
git clone https://github.com/clevercactus-dev/docker-lean-postgis.git
cd docker-lean-postgis
# Build the image
docker build -t docker-lean-postgis:latest .docker buildx create --name mybuilder --use
docker buildx build --platform linux/amd64,linux/arm64 -t docker-lean-postgis:latest .The repository includes a comprehensive test script that verifies:
- Core PostGIS functionality
- Spatial operations
- Excluded features are properly removed
- Image size
Run the tests with:
./test-image.shContributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
- Keep the image size as small as possible
- Maintain compatibility with the official PostgreSQL image
- Add comprehensive tests for new features
- Document any new features or changes
This project is licensed under the MIT License - see the LICENSE file for details.