Przejdลบ do treล›ci

๐Ÿงฉ Docker Compose

Documentation covering definition, orchestration and management of multiโ€‘container applications using Docker Compose.


๐Ÿš€ Essential Commands

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Start services in detached mode
docker compose up -d

# Stop and remove containers
docker compose down

# Rebuild images and start services
docker compose up -d --build

# Restart all services
docker compose restart

# Show container status
docker compose ps

๐Ÿงฉ Key Options in compose.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
services:
  app:
    image: myapp:latest
    restart: unless-stopped

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

    networks:
      - traefik-net

networks:
  traefik-net:
    external: true

Notes:

  • restart: unless-stopped โ€” recommended for production workloads
  • healthcheck โ€” ensures the service is marked healthy before other services depend on it
  • external: true โ€” the network must exist beforehand

๐Ÿ” Restart Policies

Policy Description Recommendation
unless-stopped Restart unless manually stopped Recommended
always Always restart, including after host reboot Critical services
on-failure Restart only on nonโ€‘zero exit code Oneโ€‘shot processes

๐Ÿ› ๏ธ Debugging & Diagnostics

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Validate and render final configuration
docker compose config

# Live logs for all services
docker compose logs -f

# Logs for a specific service
docker compose logs -f app

# Detailed container information
docker compose ps -a
docker compose top

๐Ÿ“˜ Additional Topics