Docker Compose
Docker Compose for local development and testing.
Basic Setup
Section titled “Basic Setup”version: "3.8"
services: gateway: build: context: . dockerfile: Dockerfile ports: - "3000:3000" environment: - NODE_ENV=production - PORT=3000 - UPSTREAM_URL=https://api.example.com healthcheck: test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"] interval: 30s timeout: 3s retries: 3 restart: unless-stoppedRun with:
docker-compose up --buildWith Redis
Section titled “With Redis”For distributed rate limiting:
version: "3.8"
services: gateway: build: . ports: - "3000:3000" environment: - NODE_ENV=production - REDIS_URL=redis://redis:6379 depends_on: redis: condition: service_healthy healthcheck: test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"] interval: 30s timeout: 3s
redis: image: redis:7-alpine ports: - "6379:6379" volumes: - redis-data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 10s timeout: 3s retries: 3
volumes: redis-data:With Local Upstream
Section titled “With Local Upstream”version: "3.8"
services: gateway: build: . ports: - "3000:3000" environment: - UPSTREAM_URL=http://api:8080
api: image: my-api:latest ports: - "8080:8080"Development Mode
Section titled “Development Mode”For hot-reload development:
version: "3.8"
services: gateway: build: context: . target: builder volumes: - ./src:/app/src command: npm run dev ports: - "3000:3000" environment: - NODE_ENV=developmentRun with:
docker-compose -f docker-compose.dev.yml up