ํ™”. 8์›” 12th, 2025

D: Docker has revolutionized how we develop and deploy applications, but when it comes to managing multiple containers, Docker Compose is the real game-changer! ๐ŸŽฎ In this comprehensive guide, we’ll explore practical Docker Compose examples to deploy interconnected services effortlessly.

Why Docker Compose? ๐Ÿค”

Docker Compose simplifies the process of defining and running multi-container applications with a single YAML file. Instead of managing each container separately with complex docker run commands, you can:

  • Define all services in docker-compose.yml
  • Configure networks and volumes
  • Set environment variables
  • Manage dependencies between containers

Basic Docker Compose File Structure ๐Ÿ“

Here’s a minimal docker-compose.yml template:

version: '3.8'
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
  db:
    image: postgres:13
    environment:
      POSTGRES_PASSWORD: example

Practical Example 1: WordPress with MySQL ๐ŸŒ

Let’s deploy a complete WordPress site with MySQL database:

version: '3.8'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpresspass
    networks:
      - wp-network

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpresspass
    networks:
      - wp-network

volumes:
  db_data:

networks:
  wp-network:
    driver: bridge

Key features demonstrated:

  • Volume persistence for database
  • Network isolation between services
  • Environment variables for configuration
  • Dependency management with depends_on

Practical Example 2: Microservices with Node.js + Redis ๐Ÿ›’

Deploy a simple e-commerce backend:

version: '3.8'

services:
  redis:
    image: redis:alpine
    ports:
      - "6379:6379"
    networks:
      - shop-net

  product-service:
    build: ./product-service
    ports:
      - "4001:4000"
    environment:
      REDIS_HOST: redis
    networks:
      - shop-net
    depends_on:
      - redis

  cart-service:
    build: ./cart-service
    ports:
      - "4002:4000"
    environment:
      REDIS_HOST: redis
    networks:
      - shop-net
    depends_on:
      - redis

networks:
  shop-net:
    driver: bridge

Advanced Features ๐Ÿ”ฅ

  1. Build Contexts:

    services:
    app:
    build:
      context: ./app
      dockerfile: Dockerfile.prod
      args:
        NODE_VERSION: 14
  2. Health Checks:

    services:
    db:
    image: postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 3s
      retries: 5
  3. Resource Limits:

    services:
    worker:
    image: worker:latest
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 512M

Best Practices ๐Ÿ†

  1. Use specific version tags (postgres:13 instead of postgres:latest)
  2. Separate sensitive data with .env files
  3. Implement health checks for service dependencies
  4. Use named volumes for persistent data
  5. Limit container resources in production

Troubleshooting Tips ๐Ÿ› ๏ธ

  • docker-compose logs [service] – View service logs
  • docker-compose config – Validate your YAML file
  • docker-compose up --build – Rebuild images
  • docker-compose down -v – Remove containers and volumes

Final Thoughts ๐Ÿ’ก

Docker Compose is incredibly powerful for local development and testing environments. For production deployments, consider:

  • Docker Swarm for clustering
  • Kubernetes for orchestration
  • AWS ECS for cloud deployments

Remember to always test your compose files thoroughly before deploying to production! ๐Ÿงช


Would you like me to elaborate on any specific aspect of Docker Compose? I can provide more advanced examples or explain particular features in greater detail! ๐Ÿ˜Š

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค