Nginx retry same end point on http_502 in Docker service Discovery Nginx retry same end point on http_502 in Docker service Discovery docker docker

Nginx retry same end point on http_502 in Docker service Discovery


I suggest you add a health check directly at container level (here)

By doing so, docker pings periodically an endpoint you specified, if it's found unhealthy it will 1) stop routing traffic to it 2) kill the container and restart a new one. Therefore you upstream will be resolved to one of the healthy containers. No need to retry.

As for your additional questions, the first one, docker won't start routing til it's healthy. The second, nginx is still useful to distribute traffic according to endpoint url. But personally nginx + swarm vip mode is not a great choice because swarm load balancer is poorly documented, it doesn't support sticky session and you can't have proxy level health check, I would use traefik instead, it has its own load balancer.