Building PostGIS and PgAdmin4 Docker Containers
In this article, I will introduce how to set up PostGIS and PgAdmin4 using Docker containers and demonstrate how to connect to PostGIS through PgAdmin4's console.
Creating Docker Compose YML File
Create the following docker-compose.yml
file:
version: '3.1'
services:
postgis:
image: postgis/postgis
container_name: postgis
ports:
- '5432:5432'
environment:
POSTGRES_PASSWORD: postgres
volumes:
- pgdata:/var/lib/postgresql/data
pgadmin4:
image: dpage/pgadmin4
container_name: pgadmin4
ports:
- '5050:80'
environment:
PGADMIN_DEFAULT_EMAIL: admin@example.com
PGADMIN_DEFAULT_PASSWORD: admin
links:
- postgis
volumes:
pgdata:
Run the following command:
$ docker compose up
This will start the containers for PostGIS and PgAdmin4.
Using PgAdmin4
Operate PgAdmin4 through the console and connect it to PostGIS.
First, open your browser and go to http://localhost:5050
. Enter your login credentials to log in.
Click on "Add New Server."
Open the "Connection" tab and enter the authentication information to connect to PostGIS. Then click the "Save" button.
You now see that PostGIS is connected.
Troubleshooting PgAdmin4 Container
Container Not Starting
If you specify non-email characters for the PGADMIN_DEFAULT_EMAIL
in the docker-compose.yml
, the container will throw an error during startup.
environment:
PGADMIN_DEFAULT_EMAIL: admin
PGADMIN_DEFAULT_PASSWORD: admin
‘admin’ does not appear to be a valid email address. Please reset the PGADMIN_DEFAULT_EMAIL environment variable and try again.
To resolve this, modify PGADMIN_DEFAULT_EMAIL
to a valid email format:
environment:
- PGADMIN_DEFAULT_EMAIL: admin
+ PGADMIN_DEFAULT_EMAIL: admin@example.com
PGADMIN_DEFAULT_PASSWORD: admin
Error When Operating pgAdmin
If you attempt to operate a PostgreSQL version that pgAdmin does not support, an error will occur.
Error retrieving the information – INTERNAL SERVER ERROR
ERROR: column rel.relhasoids does not exist
LINE 8: pg_get_userbyid(rel.relowner) AS relowner, rel.relhasoids,…
For example, pgAdmin 5.7 does not support PostgreSQL 14.
References