Skip to content

Instantly share code, notes, and snippets.

@hucancode
Created April 23, 2022 01:36
Show Gist options
  • Save hucancode/6fc8aecd1e22b2c8d1fa1ed14c8f751a to your computer and use it in GitHub Desktop.
Save hucancode/6fc8aecd1e22b2c8d1fa1ed14c8f751a to your computer and use it in GitHub Desktop.
Load balancer example with Docker
version: "3"
services:
db:
image: postgres:latest
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
# ... other environment variables
my-service:
image: "my-service:latest"
environment:
DB_USER: user
DB_PASSWORD: password
# ... other environment variables
depends_on:
- db
expose:
- "5000"
nginx:
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- my-service
ports:
- "4000:4000"
user nginx;
events {
worker_connections 1000;
}
http {
server {
listen 4000;
location / {
proxy_pass http://my-service:5000;
}
}
}
# fire up 5 service instances, automatically balanced
docker-compose up --scale my-servic=5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment