Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/DevOps & cloud

Docker Compose: Orchestrating Multi-Container Applications

Define and run multi-container applications with Docker Compose — databases, caches, queues, and your app in one command.

22 February 20261 min readDevOps & cloudاقرأ بالعربية

On this page

  1. A Complete Laravel Stack
  2. Key Commands
  3. Health Checks
  4. Profiles for Optional Services

Docker Compose lets you define your entire application stack in a single YAML file and spin everything up with one command. It is the standard for local development environments.

A Complete Laravel Stack

yaml
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    volumes:
      - .:/var/www/html
    depends_on:
      - mysql
      - redis
    environment:
      DB_HOST: mysql
      REDIS_HOST: redis
    networks:
      - app-network

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: laravel
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - "3306:3306"
    networks:
      - app-network

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    networks:
      - app-network

  queue:
    build: .
    command: php artisan queue:work --tries=3
    depends_on:
      - mysql
      - redis
    networks:
      - app-network

volumes:
  mysql_data:

networks:
  app-network:
    driver: bridge

Key Commands

bash
# Start all services in background
docker compose up -d

# View logs from all services
docker compose logs -f

# Rebuild after Dockerfile changes
docker compose up -d --build

# Stop and remove everything
docker compose down

# Stop and remove including volumes
docker compose down -v

Health Checks

yaml
mysql:
  image: mysql:8.0
  healthcheck:
    test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
    interval: 10s
    timeout: 5s
    retries: 5

Profiles for Optional Services

yaml
mailpit:
  image: axllent/mailpit
  profiles: ["debug"]
  ports:
    - "8025:8025"
bash
# Only starts debug-profile services
docker compose --profile debug up -d

Compose keeps your entire development environment reproducible and shareable with your team.

All articles

Keep reading

  • Docker for Developers: From Zero to Containerized Applications28 February 20261 min read
  • CI/CD Pipelines with GitHub Actions: Automate Everything22 February 20261 min read
  • Clean Code Principles: Write Code That Humans Can Read22 February 20261 min read