con un clic
dokploy-health-patterns
// Health check patterns for different service types in Dokploy templates. Covers HTTP, PostgreSQL, MongoDB, Redis, MySQL, and custom health checks.
// Health check patterns for different service types in Dokploy templates. Covers HTTP, PostgreSQL, MongoDB, Redis, MySQL, and custom health checks.
Integrate Cloudflare services with Dokploy templates: R2 storage, DNS challenge for SSL, Zero Trust Access, Workers, WAF, and Tunnel. Default to CF services for external dependencies.
Generate Docker Compose files following Dokploy conventions with proper networking, volumes, and service patterns. Use when creating new Dokploy templates or converting existing compose files.
Environment variable patterns for Dokploy templates including required vs optional syntax, secrets, connection strings, and configuration organization.
Multi-service architecture patterns for Dokploy templates including dependency chains, service communication, and complex stack design. Use when building templates with 2+ services.
Multi-tenancy patterns for Dokploy templates with network isolation: separate docker networks per tenant, shared infrastructure, and tenant-specific configuration.
Security best practices for Dokploy templates: secrets management, network isolation, least privilege, image security, and hardening recommendations.
| name | dokploy-health-patterns |
| description | Health check patterns for different service types in Dokploy templates. Covers HTTP, PostgreSQL, MongoDB, Redis, MySQL, and custom health checks. |
| version | 1.0.0 |
| author | Home Lab Infrastructure Team |
service_healthyservice_started instead)Every health check follows this structure:
healthcheck:
test: ["CMD", "command", "args"]
interval: 30s # How often to check
timeout: 10s # Max time per check
retries: 3 # Failures before unhealthy
start_period: 30s # Grace period for startup
Configuration Guidelines:
| Parameter | Default | When to Adjust |
|---|---|---|
interval | 30s | Increase for resource-constrained systems |
timeout | 10s | Increase for slow-starting services |
retries | 3 | Increase for flaky services |
start_period | 30s | Increase for complex services (databases, Java apps) |
For services with HTTP endpoints (most web apps):
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:${PORT}/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
Variations:
# With specific health endpoint
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
# With API endpoint
test: ["CMD", "curl", "-f", "http://localhost:3000/api/healthz"]
# Silent output
test: ["CMD", "curl", "-sf", "http://localhost:8080/ping"]
For Alpine-based images without curl:
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:${PORT}"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
Example (Paaster):
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
Variations:
# With specific host
test: ["CMD-SHELL", "pg_isready -U postgres -d mydb -h localhost"]
# With default user
test: ["CMD-SHELL", "pg_isready -U postgres"]
# With environment variable interpolation
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-postgres}"]
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
Variations:
# For older MongoDB (pre-6.0, use mongo instead of mongosh)
test: ["CMD", "mongo", "--eval", "db.adminCommand('ping')"]
# With authentication
test: ["CMD", "mongosh", "-u", "admin", "-p", "${MONGO_PASSWORD}", "--eval", "db.adminCommand('ping')"]
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s # Redis starts fast
Variations:
# With password
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
# Check specific key exists
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
Variations:
# With credentials
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}"]
# Using mysql client
test: ["CMD-SHELL", "mysql -u root -p${MYSQL_ROOT_PASSWORD} -e 'SELECT 1'"]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9200/_cluster/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s # ES takes longer to start
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
For complex checks using shell scripting:
healthcheck:
test: ["CMD-SHELL", "command1 && command2 || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
Example (ANyONe Relay):
healthcheck:
test: ["CMD-SHELL", "echo 'GETINFO status/circuit-established' | nc -q 1 localhost 9051 | grep -q '250' || exit 1"]
interval: 60s
timeout: 15s
retries: 3
start_period: 120s
services:
paaster:
image: wardpearce/paaster:3.1.7
depends_on:
mongodb:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
mongodb:
image: mongo:7
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
services:
paperless:
image: ghcr.io/paperless-ngx/paperless-ngx:2.13
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
gotenberg:
condition: service_started # Helper, doesn't need healthy
tika:
condition: service_started # Helper, doesn't need healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s # Longer for complex app
postgres:
image: postgres:16-alpine
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-paperless} -d ${POSTGRES_DB:-paperless}"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
redis:
image: redis:7-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s # Redis is fast
gotenberg:
image: gotenberg/gotenberg:8
# No healthcheck needed - stateless helper
tika:
image: apache/tika:2.9.1.0
# No healthcheck needed - stateless helper
services:
forgejo:
image: codeberg.org/forgejo/forgejo:9
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/healthz"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
postgres:
image: postgres:16-alpine
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${FORGEJO_DB_USER:-forgejo} -d ${FORGEJO_DB_NAME:-forgejo}"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
| Service Type | Recommended start_period |
|---|---|
| Redis | 10s |
| Static file server | 10s |
| Simple web app | 30s |
| Node.js app | 30s |
| PostgreSQL | 30s |
| MongoDB | 30s |
| MySQL | 45s |
| Java/Spring Boot | 60-120s |
| Paperless-ngx | 60s |
| Elasticsearch | 60-120s |
| Custom services | Test and adjust |
service_healthydepends_on:
database:
condition: service_healthy
Use for:
service_starteddepends_on:
helper:
condition: service_started
Use for:
service_healthy condition# Check health status
docker compose ps
# View health check logs
docker inspect --format='{{json .State.Health}}' container_name
Issue: curl not available in Alpine images Solution: Use wget for Alpine, curl for Debian/Ubuntu
Issue: Service marked unhealthy during startup Solution: Increase start_period for slow-starting services
Issue: Health check fails, service works Solution: Use internal container port, not mapped port
Issue: Shell commands fail
Solution: Use ["CMD-SHELL", "cmd | grep ..."] for pipes/redirects
Issue: 401/403 errors in health check Solution: Use unauthenticated health endpoint or add credentials
This skill is part of the skills-first architecture - loaded during Generation phase to add health checks after routing configuration.
dokploy-compose-structure: Service dependenciesdokploy-multi-service: Complex dependency chains/dokploy-create command: Phase 3 (Generation) - Step 3dokploy-compose-structure: Create base structuredokploy-traefik-routing: Add routing labelsdokploy-cloudflare-integration: Add CF integration (if applicable)dokploy-environment-config: Configure environmentdokploy-template-toml: Create template.tomlSee: .claude/commands/dokploy-create.md for full workflow