Skip to main content

Estrutura

version: '3.8'

services:
  web:
    build: .
    ports:
      - "80:80"
      - "443:443"
    environment:
      - NODE_ENV=production
    depends_on:
      - db
    networks:
      - app-network

  db:
    image: postgres:15-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: myapp
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password

volumes:
  postgres_data:

networks:
  app-network:
    driver: bridge

Comandos

# Iniciar
docker-compose up

# Background
docker-compose up -d

# Rebuild
docker-compose up --build

# Parar
docker-compose down

# Logs
docker-compose logs -f

# Executar em serviço
docker-compose exec web ls

depends_on

services:
  app:
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:15-alpine
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

Profiles

services:
  migrate:
    profiles:
      - maintenance
docker-compose --profile maintenance up

Healthcheck

services:
  web:
    image: nginx:alpine
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/health"]
      interval: 30s
      timeout: 10s
      retries: 3