This repository provides multi-version Docker images for PostgreSQL with the pgTAP extension pre-installed. pgTAP is a unit testing framework for PostgreSQL that allows you to write tests for your database in a familiar TAP (Test Anything Protocol) format.
- Multi-version support: PostgreSQL 18 and 17 images available
- Multi-platform: Supports linux/arm/v7, linux/arm64/v8, and linux/amd64
- Multiple variants: Standard (Debian), Bookworm, and Trixie images
- pgTAP pre-installed: Ready-to-use testing framework
- Auto-configured: pgTAP extension enabled automatically on startup
- Production-ready: Based on official PostgreSQL images
pgTAP is a unit testing framework for PostgreSQL that provides a set of functions for writing tests in SQL. It supports functions like ok(), is(), and isnt() to test database objects, queries, and logic.
TAP, the Test Anything Protocol, is a simple text-based interface between testing modules in a test harness. It decouples the reporting of errors from the presentation of the reports.
pshaddel/postgres-pgtap:latest(same as 18.0)pshaddel/postgres-pgtap:18orpshaddel/postgres-pgtap:18.0pshaddel/postgres-pgtap:18.0-bookwormorpshaddel/postgres-pgtap:bookwormpshaddel/postgres-pgtap:18.0-trixieorpshaddel/postgres-pgtap:trixie
pshaddel/postgres-pgtap:17orpshaddel/postgres-pgtap:17.6pshaddel/postgres-pgtap:17.6-bookwormpshaddel/postgres-pgtap:17.6-trixie
You can pull any of the available images from Docker Hub:
# Latest PostgreSQL 18 (recommended)
docker pull pshaddel/postgres-pgtap:latest
# Specific versions
docker pull pshaddel/postgres-pgtap:18
docker pull pshaddel/postgres-pgtap:17
# Debian variants
docker pull pshaddel/postgres-pgtap:bookworm
docker pull pshaddel/postgres-pgtap:17.6-bookwormRun the container with the following command:
docker run -d --name my_postgres_pgtap \
-e POSTGRES_USER=myuser \
-e POSTGRES_PASSWORD=mypassword \
-e POSTGRES_DB=mydb \
-p 5432:5432 \
pshaddel/postgres-pgtap:latestYou can access the database in two ways:
-
Using a shell inside the container:
docker exec -it my_postgres_pgtap shThen, use
psqlto connect to the database:psql -U myuser -d mydb
-
Using a PostgreSQL client:
Connect to the database using the environment variables and the exposed port:
psql -h localhost -p 5432 -U myuser -d mydb
Once connected to the database, you can verify that the pgTAP extension is installed and get its version:
-- Check if pgTAP extension is available
SELECT * FROM pg_available_extensions WHERE name = 'pgtap';
-- Get pgTAP version (it's pre-enabled in these images)
SELECT pgtap_version();You should see pgTAP listed as an available extension and the version should return 1.3.
To write tests, you can use pgTAP functions like ok(), is(), and isnt(). For example:
SELECT plan(2);
SELECT ok(1 = 1, '1 equals 1');
SELECT is(2 + 2, 4, '2 plus 2 equals 4');
SELECT * FROM finish();If you want to build the images locally, clone this repository and run the build script:
# Make the script executable
chmod +x build-all-versions.sh
# Build all versions and push to Docker Hub (requires login)
./build-all-versions.shOr build specific versions manually:
# Build PostgreSQL 18 locally (for testing)
docker build -t local-postgres-pgtap-18 -f test-dockerfile-18 .
# Build PostgreSQL 17 locally
docker build -t local-postgres-pgtap-17 -f dockerfile .The build process performs different steps depending on the PostgreSQL version:
- Starts with the official PostgreSQL 18 image
- Installs
postgresql-17-pgtappackage (since 18-specific package isn't available yet) - Copies pgTAP extension files from PostgreSQL 17 directories to PostgreSQL 18 directories
- Enables the
pgTAPextension automatically on container startup
- Starts with the official PostgreSQL 17 image
- Installs
postgresql-17-pgtappackage directly - Enables the
pgTAPextension automatically on container startup
All images are built for multiple architectures:
linux/amd64(Intel/AMD 64-bit)linux/arm64/v8(ARM 64-bit, Apple Silicon, etc.)linux/arm/v7(ARM 32-bit)
This repository includes automated workflows that:
- Daily checks: Automatically check for new PostgreSQL versions every day at 2 AM UTC
- Auto-building: Automatically build and push new images when updates are detected
- Pull requests: Create pull requests with version updates for review
- Multi-version support: Handle both PostgreSQL 18 and 17 updates independently
The automation ensures that the latest PostgreSQL versions with pgTAP are always available.
If you encounter any issues:
-
Ensure that the required ports (default:
5432) are not blocked by your firewall. -
Verify that the environment variables (
POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB) are correctly set. -
Check the container logs for errors:
docker logs my_postgres_pgtap
This project is licensed under the MIT License.