Building a Docker Compose Template Library for Your Homelab
Create reusable Docker Compose templates for rapid deployment. Learn to build a personal library of self-hosted service configurations with best practices.
Posted by
Related reading
Private Cloud vs Public Cloud: When to Self-Host and When Not To
Understand when self-hosting makes sense and when public cloud is better. A practical guide to choosing between private cloud homelab and AWS/GCP/Azure services.
Homelab Documentation: Wiki.js vs BookStack for Self-Hosted Wikis
Document your homelab setup with self-hosted wikis. Compare Wiki.js and BookStack for creating searchable documentation of your infrastructure and procedures.
Docker Security Scanning: Trivy and Dockle for Safe Containers
Scan your Docker images for vulnerabilities before deploying. Learn to use Trivy and Dockle to secure your self-hosted homelab container infrastructure.

Why Build a Template Library?
Every time you deploy a new service, you start from scratch - searching for compose files, figuring out volumes, setting up networks. A personal template library saves hours and ensures consistency.
Directory Structure
homelab-templates/ ├── templates/ │ ├── databases/ │ │ ├── postgres.yml │ │ ├── mysql.yml │ │ └── redis.yml │ ├── media/ │ │ ├── jellyfin.yml │ │ └── plex.yml │ ├── productivity/ │ │ ├── nextcloud.yml │ │ └── vaultwarden.yml │ └── monitoring/ │ ├── uptime-kuma.yml │ └── grafana-stack.yml ├── base/ │ ├── networks.yml │ └── common.yml ├── .env.example └── README.md
Base Template with Extensions
# base/common.yml
x-common: &common
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# templates/databases/postgres.yml
services:
postgres:
<<: *common
image: postgres:15-alpine
environment:
- POSTGRES_USER=${DB_USER:-postgres}
- POSTGRES_PASSWORD=${DB_PASSWORD:?Required}
- POSTGRES_DB=${DB_NAME:-app}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
volumes:
postgres_data:Deployment Script
#!/bin/bash # deploy.sh - Deploy from templates SERVICE=$1 if [ -z "$SERVICE" ]; then echo "Usage: ./deploy.sh <service>" exit 1 fi TEMPLATE=$(find templates -name "$SERVICE.yml" | head -1) if [ -z "$TEMPLATE" ]; then echo "Template not found: $SERVICE" exit 1 fi mkdir -p ~/homelab/$SERVICE cp $TEMPLATE ~/homelab/$SERVICE/docker-compose.yml cp .env.example ~/homelab/$SERVICE/.env echo "Deployed $SERVICE to ~/homelab/$SERVICE" echo "Edit .env and run: docker compose up -d"
