PostgreSQL base image with embedded data support and replication
1.4K
A PostgreSQL Docker image built from Alpine Linux with embedded data capability. This base image contains no volumes, allowing schema and data to be baked directly into derived images.
# Pull from Docker Hub (automatically selects the right architecture)
docker pull tstangenberg1/postgres-base:latest
# Run the container
docker run -d --name postgres -p 5432:5432 tstangenberg1/postgres-base:latest
# Connect to PostgreSQL
docker exec -it postgres psql -U postgres
This image supports multiple architectures:
linux/amd64 - Intel/AMD 64-bit (x86_64)linux/arm64 - ARM 64-bit (Apple Silicon M1/M2, AWS Graviton, Raspberry Pi 4)Docker automatically pulls the correct image for your platform.
Images are automatically built and published to Docker Hub:
tstangenberg1/postgres-base:latest - Latest build from main branchtstangenberg1/postgres-base:17-alpine - PostgreSQL 17 on Alpinetstangenberg1/postgres-base:1.0.0 - Specific version releases (when tagged)tstangenberg1/postgres-base:1.0 - Minor versiontstangenberg1/postgres-base:1 - Major versionAll tags support both linux/amd64 and linux/arm64 architectures.
If you want to build the image locally:
# Single platform build
docker build -t postgres-base:17-alpine .
# Multi-platform build (requires buildx)
docker buildx build --platform linux/amd64,linux/arm64 -t postgres-base:17-alpine .
# Pull and run from Docker Hub
docker run -d --name postgres -p 5432:5432 tstangenberg1/postgres-base:latest
# Connect to the database
docker exec -it postgres psql -U postgres
# Check PostgreSQL version
docker exec postgres psql -U postgres -c "SELECT version();"
The image includes postgresql-contrib which provides extensions such as:
pg_stat_statements - Track planning and execution statisticspgcrypto - Cryptographic functionshstore - Key-value storeuuid-ossp - UUID generationbtree_gist - GiST index support for btreeTo enable an extension:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
POSTGRES_USER - Default: postgresPOSTGRES_DB - Default: postgresPGDATA - Default: /var/lib/postgresql/dataThis image is pre-configured for PostgreSQL replication with the following settings:
logical - Supports both physical and logical replication10 - Up to 10 concurrent replication connections10 - Supports replication slots for reliable streamingon - Standby servers can accept read-only queriesThe image is configured to accept replication connections from any host using MD5 authentication:
host replication all 0.0.0.0/0 md5
This makes it easy to set up streaming replication or logical replication between containers.
This image is designed to be used as a base for creating images with embedded schema and data:
FROM tstangenberg1/postgres-base:latest
# Copy your SQL initialization scripts
COPY init-scripts/01-schema.sql /tmp/
COPY init-scripts/02-data.sql /tmp/
# Run scripts to populate the database
USER root
RUN chown postgres:postgres /tmp/*.sql
USER postgres
RUN pg_ctl -D "$PGDATA" -o "-c listen_addresses=''" -w start && \
psql -U postgres -d postgres -f /tmp/01-schema.sql && \
psql -U postgres -d postgres -f /tmp/02-data.sql && \
pg_ctl -D "$PGDATA" -m fast -w stop && \
rm /tmp/*.sql
docker build -t my-app-db:v1.0 .
docker run -d --name my-app-db -p 5432:5432 my-app-db:v1.0
Expected size: ~50-80 MB (depending on Alpine package versions)
The image includes a health check that runs every 30 seconds:
pg_isready -U postgres
Check health status:
docker inspect --format='{{json .State.Health}}' <container-name>
postgres user (UID 70)✅ Good for:
❌ Not suitable for:
# Check logs
docker logs <container-name>
# Verify PostgreSQL is running
docker exec <container-name> pg_isready -U postgres
# Check if port is exposed
docker port <container-name>
# Test connection from host
psql -h localhost -U postgres -d postgres
docker exec <container-name> psql -U postgres -c "SELECT * FROM pg_available_extensions;"
This project is licensed under the MIT License - see the LICENSE file for details.
This image uses PostgreSQL and Alpine Linux, both under their respective open-source licenses.
Content type
Image
Digest
sha256:97ac2be49…
Size
22.3 MB
Last updated
7 months ago
docker pull tstangenberg1/postgres-base