What network settings do you have setup for docker? I tried what you have, but it wouldn't load balance as I would expect. I have nginx setup to serve on port 5100 and my dotnet app on 5000.
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types; #include the required MIME types
sendfile on;
# List of application servers
upstream api {
server api1:5000;
server api2:5000;
server api3:5000;
}
# Configuration for the server
server {
# Running port
listen 5100;
# Proxying the connections
location / {
proxy_pass http://api;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
172.22.0.1 - - [01/Nov/2017:17:31:20 +0000] "GET /api/values HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
2017/11/01 17:31:20 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.22.0.1, server: , request: "GET /api/values HTTP/1.1", upstream: "http://127.0.0.1:5000/api/values", host: "api:5100"
I suspect that the bridged mode networking is causing some issues here.