Skip to content

Conversation

@bobbyonmagic
Copy link
Collaborator

Overview

Enhanced the docker-compose.yaml file with Docker Compose best practices for improved reliability, security, and maintainability.

Changes Made

1. Version Specification

  • Added version: '3.9' for better compatibility and explicit version control

2. Build Configuration

  • Added explicit build args for version pinning:
    • NODE_VERSION: 20.18.1
    • PNPM_VERSION: 10.11.1
    • NGINX_VERSION: 1.27-alpine (prod only)
  • Added image tags for better image management (devops-daily:dev, devops-daily:prod)

3. Networking

  • Added custom bridge network (devops-daily-network)
  • Provides better service isolation and communication
  • Named network for easier debugging

4. Health Checks

Dev service:

healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:3000"]
  interval: 30s
  timeout: 10s
  retries: 3
  start_period: 40s

Prod service:

healthcheck:
  test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:80/"]
  interval: 30s
  timeout: 3s
  retries: 3
  start_period: 5s

5. Resource Limits

Prevents resource exhaustion and runaway containers:

Dev service:

  • Limit: 2 CPU cores, 4GB RAM
  • Reservation: 1 CPU core, 2GB RAM

Prod service:

  • Limit: 1 CPU core, 1GB RAM
  • Reservation: 0.5 CPU cores, 512MB RAM

6. Logging Configuration

logging:
  driver: "json-file"
  options:
    max-size: "10m"
    max-file: "3"
  • Prevents unlimited log growth
  • Rotates after 10MB per file
  • Keeps 3 log files (30MB total per container)

7. Container Labels

Added descriptive labels for better organization:

labels:
  - "com.devops-daily.service=dev"
  - "com.devops-daily.environment=development"

8. Security Improvements

  • Fixed pnpm store path: /root/.local/share/pnpm/store/app/.pnpm-store
  • Removed requirement for root user in development

9. Documentation

  • Added .env.example file documenting all environment variables
  • Developers can copy to .env and customize

Benefits

Reliability: Health checks ensure services are actually responding, not just running
Resource Management: Prevents containers from consuming all system resources
Log Management: Automatic log rotation prevents disk space issues
Security: Non-root paths for development container
Maintainability: Labels and explicit configuration make debugging easier
Consistency: Build args ensure same versions as standalone Dockerfiles
Network Isolation: Custom network provides better service communication

Testing

# Test dev service
docker compose up dev

# Test prod service
docker compose up prod

# Check health status
docker ps

# View logs with rotation
docker compose logs dev

Compatibility

All changes are backward compatible. Existing workflows will continue to function.

Related

Enhancements:
- Add version specification (3.9) for better compatibility
- Add explicit build args for all services (NODE_VERSION, PNPM_VERSION, NGINX_VERSION)
- Add image tags for better image management
- Add custom network (devops-daily-network) for service isolation
- Add health checks for both dev and prod services
- Add resource limits (CPU and memory) to prevent resource exhaustion
- Add logging configuration (10MB max, 3 files) for log rotation
- Add descriptive labels for better container organization
- Fix pnpm store path to be non-root (/app/.pnpm-store)
- Add .env.example file for environment variable documentation

Best practices implemented:
- Explicit health checks with appropriate intervals and timeouts
- Resource constraints to prevent runaway containers
- Structured logging with rotation
- Named networks for better networking control
- Descriptive labels for container management
- Build args for version pinning consistency
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 6, 2025

Deploying devops-daily with  Cloudflare Pages  Cloudflare Pages

Latest commit: c173278
Status:⚡️  Build in progress...

View logs

@bobbyonmagic bobbyonmagic merged commit 8a3a022 into main Dec 6, 2025
2 of 3 checks passed
@bobbyonmagic bobbyonmagic deleted the fix/docker-compose-improvements branch December 6, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants