Self-Hosting PostgreSQL, Redis, and MinIO for $0: Docker Compose Production Blueprint
When launching a new web application, modern developers are immediately nudged toward managed cloud infrastructure: AWS RDS for PostgreSQL ($30–$80/mo), Upstash or Redis Cloud ($15–$30/mo), and Amazon S3 ($5–$20/mo plus egress fees). Before your application acquires its first 100 users, your infrastructure bill is already running at $60 to $150 every month.
Yet on modern cloud VPS architectures—including generous free tiers like Oracle Cloud's Always Free Ampere instances (4 OCPUs, 24 GB RAM, 200 GB NVMe disk)—you can run a rock-solid, fully containerized production data stack for literally zero dollars.
In this engineering blueprint from The Zero-Dollar Dev, we provide our battle-tested, production-ready docker-compose.yml setup running PostgreSQL 16, Redis 7, MinIO (S3-compatible object storage), and Caddy (automated Let's Encrypt TLS) with automated encrypted backups to Cloudflare R2.
1. The Multi-Service Architecture Blueprint
Our stack runs four isolated services on a dedicated Docker bridge network with healthchecks, persistent volume mounts, and automated SSL termination:
| Service | Image / Version | Primary Role | Internal Port | Memory Cap |
|---|---|---|---|---|
| PostgreSQL | postgres:16-alpine |
Primary relational ACID database | 5432 |
2.0 GB |
| Redis | redis:7.2-alpine |
Session store, API rate-limiting, and queue broker | 6379 |
512 MB |
| MinIO | minio/minio:RELEASE.2024-08-03 |
S3-compatible object storage for file/image uploads | 9000 (API) / 9001 (Console) |
1.0 GB |
| Caddy | caddy:2-alpine |
Reverse proxy with automatic Let's Encrypt TLS | 80 / 443 |
128 MB |
2. Production docker-compose.yml
Save the following configuration as docker-compose.yml in your server's project directory:
version: "3.8"
networks:
backend-net:
driver: bridge
volumes:
postgres_data:
redis_data:
minio_data:
caddy_data:
caddy_config:
services:
# ========================================================
# 1. PostgreSQL 16
# ========================================================
postgres:
image: postgres:16-alpine
container_name: prod_postgres
restart: unless-stopped
networks:
- backend-net
environment:
POSTGRES_DB: ${POSTGRES_DB:-app_production}
POSTGRES_USER: ${POSTGRES_USER:-app_user}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Required}
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- postgres_data:/var/lib/postgresql/data
command: >
postgres -c shared_buffers=512MB
-c effective_cache_size=1536MB
-c maintenance_work_mem=128MB
-c checkpoint_completion_target=0.9
-c wal_buffers=16MB
-c default_statistics_target=100
-c random_page_cost=1.1
-c effective_io_concurrency=200
-c work_mem=16MB
-c min_wal_size=1GB
-c max_wal_size=4GB
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-app_user} -d ${POSTGRES_DB:-app_production}"]
interval: 10s
timeout: 5s
retries: 5
# ========================================================
# 2. Redis 7.2
# ========================================================
redis:
image: redis:7.2-alpine
container_name: prod_redis
restart: unless-stopped
networks:
- backend-net
command: >
redis-server --requirepass ${REDIS_PASSWORD:?Required}
--maxmemory 512mb
--maxmemory-policy allkeys-lru
--appendonly yes
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD:?Required}", "ping"]
interval: 10s
timeout: 5s
retries: 5
# ========================================================
# 3. MinIO S3-Compatible Storage
# ========================================================
minio:
image: minio/minio:RELEASE.2024-08-03T04-33-55Z
container_name: prod_minio
restart: unless-stopped
networks:
- backend-net
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-admin}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Required}
MINIO_BROWSER_REDIRECT_URL: https://${MINIO_CONSOLE_DOMAIN}
volumes:
- minio_data:/data
command: server /data --console-address ":9001"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 15s
timeout: 5s
retries: 3
# ========================================================
# 4. Caddy Reverse Proxy & Automatic TLS
# ========================================================
caddy:
image: caddy:2-alpine
container_name: prod_caddy
restart: unless-stopped
networks:
- backend-net
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
minio:
condition: service_healthy
3. The Caddyfile: Instant HTTPS for MinIO & APIs
Create a Caddyfile alongside your docker compose configuration to expose MinIO's S3 API and web console securely:
# MinIO S3 API Endpoint (Point your AWS SDK here)
s3.yourdomain.com {
reverse_proxy minio:9000 {
header_up Host {upstream_hostport}
header_up X-Real-IP {remote_host}
}
}
# MinIO Web Admin Console
console-s3.yourdomain.com {
reverse_proxy minio:9001 {
header_up Host {upstream_hostport}
header_up X-Real-IP {remote_host}
}
}
4. The Zero-Dollar Backup Protocol (Automated R2 Mirroring)
Self-hosting is only as good as your disaster recovery plan. Never store backups on the same disk as your database. We use a lightweight cron script that runs nightly, dumps PostgreSQL, and streams the encrypted archive directly into a Cloudflare R2 bucket (which includes 10GB of free storage and 0 egress fees):
#!/usr/bin/env bash
set -eo pipefail
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BACKUP_DIR="/tmp/backups"
BACKUP_FILE="${BACKUP_DIR}/db_backup_${TIMESTAMP}.sql.gz"
mkdir -p "${BACKUP_DIR}"
echo "[*] Dumping PostgreSQL database..."
docker exec -t prod_postgres pg_dumpall -c -U app_user | gzip -9 > "${BACKUP_FILE}"
echo "[*] Syncing to Cloudflare R2 via rclone..."
rclone copy "${BACKUP_FILE}" r2-backup:app-backups/daily/
echo "[*] Cleaning local temporary backup..."
rm -f "${BACKUP_FILE}"
# Keep only last 14 days of backups in R2
rclone delete --min-age 14d r2-backup:app-backups/daily/
echo "[+] Backup successfully synced to Cloudflare R2."
5. Cost Comparison: Self-Hosted vs Managed Cloud
| Infrastructure Component | AWS / Managed Cloud | Zero-Dollar Self-Hosted Blueprint |
|---|---|---|
| PostgreSQL Database | AWS RDS db.t4g.small ($34/mo) | $0.00 (Docker container) |
| Redis In-Memory Cache | Upstash Pro / ElastiCache ($18/mo) | $0.00 (Docker container) |
| Object Storage (S3) | AWS S3 + Egress ($12/mo) | $0.00 (MinIO + Cloudflare R2 backup) |
| SSL & Reverse Proxy | AWS Application Load Balancer ($22/mo) | $0.00 (Caddy Let's Encrypt) |
| TOTAL MONTHLY EXPENSE | $86.00 / month | $0.00 / month ($0.00/year) |
6. Related Zero-Dollar Infrastructure Guides
- The Zero-Dollar Production Stack: Deploy Full-Stack Web Apps for $0 in 2026
- The Zero-Dollar SaaS Audit: How to Cancel $350/Month in Forgotten Subscriptions
- 24 Paid Business Tools Replaced With Free Tiers (Where Each One Breaks)
- Notion vs AppFlowy vs AFFiNE: The Best Free Local-First Knowledge Base for Solo Developers
☕ Support Independent Engineering Blueprints
Every Docker script, configuration template, and architectural guide on The Zero-Dollar Dev is published 100% free with zero paywalls.
If this Docker Compose blueprint saved your project from a monthly cloud database bill, consider supporting our ongoing research:
- ⚡ Download the $1.00 Zero-Dollar Business Stack on Ko-fi: Pre-configured Docker Compose files, Caddyfiles, and automated backup scripts.
- 🛠️ Request a Custom Server Infrastructure Review ($1.00 Commission): Get your self-hosted setup audited for security, backup integrity, and memory tuning.
- 💳 Send a Direct $1.00 PayPal Tip: Clean, direct support.
Comments
Post a Comment