Using Docker Compose for PostgreSQL
Docker is a great software solution for containerization of other software.
I'm using it for my private services, like
- Teslamate, a logging and visulalization software for Teslas
- NGinx Proxy Manager, a great tool for the management of web services, including certification management
- Ghost, a blogging service
- and many more
Additionally, I use it to test new RDBMS releases, like PostgreSQL.
As I'm much too lazy to drop and recreate containers when I want to update them, I'm using Docker Compose for that. So here's my Docker Compose file to create a Docker container for each PostgreSQL Release since version 12. Here the version 17 part:
services:
psql_17:
image: postgres:17
hostname: psql_17
restart: always
environment:
POSTGRES_PASSWORD: XXXXXXXX
ports:
- 65432:5432
networks:
- proxiable
You can add a complete part for every version - or the same version, depending on what you want to test. But remember to expose a unique port for each service block. In my case, port 5432 is exposed to 65432.
To upgrade to the latest version available on DockerHub (or somewhere else in the internet - see the "image" part), I only have to execute
# docker compose pull
If there's a newer image, or my configuration changed, I have to (re)start it:
# docker compose up -d
As I'm lazy, I do these commands in one line:
# docker compose pull && docker compose up -d --remove-orphans && docker compose logs -f --tail 30
--remove-orphans
means that old parts are automatically removed. And docker compose logs -f
shows the logfile right afterstarting.
Please keep in mind: Do not upgrade PostgreSQL containers, e. g. from image postgres:16
to postgres:17
, because PostgreSQL needs a specific upgrade path. The easiest way to upgrade to a newer major version is to use pg_dump
and pg_restore
.