Skip to content

Commit 0fae22a

Browse files
committed
feat(docker): upgrade to PostgreSQL 18 and PostGIS 3.6.2
- Updated base image to `postgres:18.2-alpine3.23` for PostgreSQL 18. - Upgraded PostGIS version to 3.6.2 for enhanced spatial features. - Adjusted `PGDATA` default path to include versioning (`/var/lib/postgresql/18/docker`). - Updated README with migration instructions for PostgreSQL 18 and new data directory structure.
1 parent c8401bd commit 0fae22a

2 files changed

Lines changed: 68 additions & 15 deletions

File tree

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
# === VARIABLES (defined once) ===
3-
# Using the latest PostgreSQL 17 Alpine image for minimal size
4-
ARG BASE_IMAGE=postgres:17.5-alpine3.22
3+
# Using the latest PostgreSQL 18 Alpine image for minimal size
4+
ARG BASE_IMAGE=postgres:18.2-alpine3.23
55
# PostgreSQL version for the base image and compatibility checks
6-
ARG PG_VERSION=17.5
7-
# PostGIS 3.5.3 provides the spatial features we need while maintaining compatibility
8-
ARG POSTGIS_VERSION=3.5.3
6+
ARG PG_VERSION=18.2
7+
# PostGIS 3.6.2 provides the spatial features we need while maintaining compatibility
8+
ARG POSTGIS_VERSION=3.6.2
99
# SHA256 checksum ensures we're getting the exact source code we expect
10-
ARG POSTGIS_SHA256=44222ed2b8f742ffc1ceb429b09ebb484c7880f9ba27bf7b6b197346cdd25437
10+
ARG POSTGIS_SHA256=607a4d21c017e5283e15d2d977c9b7f575ddfc672afdee81fc84a2d823db4ba5
1111

1212
# === BUILD STAGE ===
1313
# Multi-stage build keeps the final image lean by excluding build tools

README.md

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Alpine Linux for minimal size while maintaining full spatial database functional
1515
- 🔄 **Multi-Architecture**: Native support for both ARM64 and AMD64 platforms
1616
- 🧪 **Thoroughly Tested**: Comprehensive test suite ensures reliability
1717
- 🔒 **Secure Base**: Built on official PostgreSQL Alpine images
18-
- 📦 **Latest Versions**: PostgreSQL 17 + PostGIS 3.5.3
18+
- 📦 **Latest Versions**: PostgreSQL 18 + PostGIS 3.6.2
1919

2020
### What's Included
2121

@@ -66,35 +66,88 @@ platform (AMD64 or ARM64).
6666

6767
### Environment Variables
6868

69-
| Variable | Description | Default |
70-
|---------------------|--------------------------------|----------------------------|
71-
| `POSTGRES_PASSWORD` | PostgreSQL password (required) | - |
72-
| `POSTGRES_USER` | PostgreSQL username | `postgres` |
73-
| `POSTGRES_DB` | Database name | `postgres` |
74-
| `PGDATA` | Data directory | `/var/lib/postgresql/data` |
69+
| Variable | Description | Default |
70+
|---------------------|--------------------------------|---------------------------------|
71+
| `POSTGRES_PASSWORD` | PostgreSQL password (required) | - |
72+
| `POSTGRES_USER` | PostgreSQL username | `postgres` |
73+
| `POSTGRES_DB` | Database name | `postgres` |
74+
| `PGDATA` | Data directory | `/var/lib/postgresql/18/docker` |
7575

7676
All standard PostgreSQL environment variables are supported. See
7777
the [official PostgreSQL Docker documentation](https://hub.docker.com/_/postgres) for more details.
7878

79+
> **Note:** Starting with PostgreSQL 18, the PGDATA path is now version-specific to enable easier
80+
> major version upgrades using `pg_upgrade --link`.
81+
7982
### Using with Docker Compose
8083

8184
```yaml
82-
version: '3'
85+
services:
86+
postgis:
87+
image: ghcr.io/clevercactus-dev/docker-lean-postgis:latest
88+
environment:
89+
POSTGRES_PASSWORD: mysecretpassword
90+
POSTGRES_DB: mydb
91+
ports:
92+
- "5432:5432"
93+
volumes:
94+
- postgis-data:/var/lib/postgresql
95+
96+
volumes:
97+
postgis-data:
98+
```
99+
100+
## 🔄 Migrating from PostgreSQL 17 to 18
101+
102+
PostgreSQL 18 introduces a breaking change in the data directory structure. If you're upgrading from
103+
a previous version of this image (PostgreSQL 17), you have two options:
104+
105+
### Option 1: Use the Old PGDATA Path (Backwards Compatible)
106+
107+
Keep using your existing volumes by explicitly setting the PGDATA environment variable:
108+
109+
```yaml
83110
services:
84111
postgis:
85112
image: ghcr.io/clevercactus-dev/docker-lean-postgis:latest
86113
environment:
87114
POSTGRES_PASSWORD: mysecretpassword
88115
POSTGRES_DB: mydb
116+
PGDATA: /var/lib/postgresql/data # Use old location
89117
ports:
90118
- "5432:5432"
91119
volumes:
92-
- postgis-data:/var/lib/postgresql/data
120+
- postgis-data:/var/lib/postgresql/data # Old mount point
93121

94122
volumes:
95123
postgis-data:
96124
```
97125
126+
### Option 2: Migrate to the New Structure (Recommended)
127+
128+
For new deployments or when you want to benefit from easier future upgrades:
129+
130+
1. **Backup your existing data:**
131+
```bash
132+
docker exec your-container pg_dumpall -U postgres > backup.sql
133+
```
134+
135+
2. **Update your docker-compose.yml to use the new volume mount:**
136+
```yaml
137+
volumes:
138+
- postgis-data:/var/lib/postgresql # New mount point
139+
```
140+
141+
3. **Start the new container and restore:**
142+
```bash
143+
docker-compose up -d
144+
docker exec -i your-container psql -U postgres < backup.sql
145+
```
146+
147+
> **Why this change?** The new versioned PGDATA path (`/var/lib/postgresql/18/docker`) enables
148+
> faster major version upgrades using `pg_upgrade --link` by keeping data directories separate per
149+
> version.
150+
98151
## 🔨 Building
99152

100153
To build the image locally:

0 commit comments

Comments
 (0)