Skip to content

Docker Compose

Docker Compose for local development and testing.

docker-compose.yml
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-stopped

Run with:

Terminal window
docker-compose up --build

For distributed rate limiting:

docker-compose.yml
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:
docker-compose.yml
version: "3.8"
services:
gateway:
build: .
ports:
- "3000:3000"
environment:
- UPSTREAM_URL=http://api:8080
api:
image: my-api:latest
ports:
- "8080:8080"

For hot-reload development:

docker-compose.dev.yml
version: "3.8"
services:
gateway:
build:
context: .
target: builder
volumes:
- ./src:/app/src
command: npm run dev
ports:
- "3000:3000"
environment:
- NODE_ENV=development

Run with:

Terminal window
docker-compose -f docker-compose.dev.yml up