
Docker PostGIS Setup: Deploy and Run a Spatial Database with Docker

PostGIS extends PostgreSQL databases, adding support for geographic data. It allows users to store, query, and manage spatial information directly within PostgreSQL. Examples of spatial data include coordinates, addresses, or geographic shapes. If an application needs geographic queries, such as finding points within a specific radius, PostGIS provides the necessary features.
This guide will demonstrate deploying PostGIS using Docker, configuring the container, and running it with Docker Compose.
PostGIS Configuration
The Docker PostGIS container is built upon the official PostgreSQL image, meaning it inherits PostgreSQL's environment variables. You can use the same environment variables as the official PostgreSQL image.
Supported Environment Variables
These variables help configure your PostGIS container at startup:
POSTGRES_PASSWORD
Mandatory setting for your PostgreSQL database password.POSTGRES_PASSWORD=mysecretpassword
POSTGRES_USER
Database administrator username (default ispostgres
if not specified).POSTGRES_USER=mydatabaseuser
POSTGRES_DB
Database created at container initialization time. Default name matches thePOSTGRES_USER
if not set.POSTGRES_DB=mygisdb
POSTGRES_INITDB_ARGS
Pass additional initialization parameters to PostgreSQL database creation commands.POSTGRES_INITDB_ARGS="--encoding=UTF8"
POSTGRES_INITDB_WALDIR
Set a separate write-ahead log directory during initialization.POSTGRES_INITDB_WALDIR=/logs
POSTGRES_HOST_AUTH_METHOD
Set host authentication method (default usesscram-sha-256
authentication).POSTGRES_HOST_AUTH_METHOD=trust
PGDATA
Specify PostgreSQL data directory location inside container.PGDATA=/var/lib/postgresql/data
Using Docker Compose
Docker Compose simplifies running multi-service containers. Use the following example to create a Docker Compose file (docker-compose.yml
) running a PostgreSQL database with PostGIS extensions enabled.
Docker Compose Example
services:
postgis:
image: postgis/postgis:16-3.4-alpine
container_name: postgis
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_DB: spatial_db
POSTGRES_USER: admin
POSTGRES_PASSWORD: secretpassword
volumes:
- postgis_data:/var/lib/postgresql/data
volumes:
postgis_data:
Run the Container
Place your docker-compose.yml
file in a directory and run the following command:
docker-compose up -d
This will pull the official PostGIS image, create a container named postgis
, configure your database (spatial_db
) with username (admin
), password (secretpassword
), and map port 5432 of your host machine.
You can now connect to your database at localhost:5432
using your PostgreSQL client or GIS tools like QGIS with these details.
Deploying on Sliplane
The easiest way to deploy a PostGIS database is on Sliplane. To get started, simply signup (free 2 day trial) and create a new service.
Select the PostGIS image, select "TCP" service and set environment variables for database name (POSTGRES_DB
), username (POSTGRES_USER
), and password (POSTGRES_PASSWORD
). Finally create a volume that mounts the PostGIS data to /var/lib/postgresql/data
. and click deploy. And thats it!
FAQ
You got questions? We got answers!
How to Check if PostGIS is Installed?
To check PostGIS installation status, connect to PostgreSQL database using psql
or other PostgreSQL client and execute:
SELECT PostGIS_version();
If correctly installed, it should return PostGIS version details, e.g.:
postgis_version
------------------------
3.4 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
Alternatively, to confirm all installed extensions within your database, run:
\dx
Look for PostGIS extensions in the returned table.
ARM CPU Support?
Official PostGIS Docker images (postgis/postgis
) have built-in ARM platform support (ARM64 architecture). ARM-based systems, such as Apple silicon Macs, Raspberry Pi, or AWS Graviton servers, can run these images reliably without issue.
Sliplane Pricing - Are There Surprise Bills?
No! Sliplane always charges a flat fee, ensuring predictable costs. The only variable cost is bandwidth usage, which is billed at a flat 2 Euros per TB (slight differences between locations).
Are Dockerized PostGIS Containers Secure?
Official PostGIS containers maintain industry-standard best practices for security. The base PostgreSQL image used maintains updated security patches from Debian or Alpine Linux OS. Consider additional practices:
- Change default Postgres passwords and use strong unique passwords.
- Limit network exposure—only expose necessary ports.
- Regularly update deployed containers to use newest available images for security patches.
- Backup regularly in case of security issues.
Sliplane and container platforms handle several security responsibilities automatically. Following recommended Docker security practices can help ensure the safety of your PostGIS deployment.