Created
April 23, 2022 01:36
-
-
Save hucancode/6fc8aecd1e22b2c8d1fa1ed14c8f751a to your computer and use it in GitHub Desktop.
Load balancer example with Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
events { | |
worker_connections 1000; | |
} | |
http { | |
server { | |
listen 4000; | |
location / { | |
proxy_pass http://my-service:5000; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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