Windows Server Docker container cannot connect to proxy container after web server restart Windows Server Docker container cannot connect to proxy container after web server restart docker docker

Windows Server Docker container cannot connect to proxy container after web server restart


Problem

web reference in the proxy container’s nginx.conf is referring to the up of the container that is referenced when nginx server was started. When web restarts the old ip becomes unavailable and a new ip is used, the container web reference is then updated, however nginx server is still referencing the old ip since configuration changes are only applied on start/restart.

Solution

You need to restart the nginx proxy server—not necessarily the container—when your web container is replaced. This can be done by using docker-gen to monitor metadata regarding containers and restart nginx when a change is detected. Luckily nginx-proxy, does this for you. nginx-proxy is well maintained, and an alternative to you having to maintain this business logic yourself.

References

Nginx Proxy: https://github.com/nginx-proxy/nginx-proxy


Nginx is caching the resolved DNS IP of web container.You can configure Nginx to invalidate DNS cache(use different TTL than the one set on DNS record) by adding resolver 127.0.0.11 valid=1s to the proxy nginx.config file.

Info on Nginx resolver: http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver