-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to tell nginx to look up a container's IP dynamically so it can be restarted without needing to also restart nginx container? #3314
Comments
I believe this is a known issue with nginx. It caches the DNS queries when it starts and never tries them again. This is why people have been developing alternative proxies/load balancers for use with containers. One example is https://github.com/containous/traefik |
Thanks for the tip @dnephin, it looks interesting. At first glance it doesn't seem to support serving static files though. I suppose there is probably something else to fill that gap as well though. I suppose I could just continue to use nginx for that. |
Well this is the simplest thing I could come up with. Not dynamic or scaleable in any way, I just set a static IP for the backend: version: '2'
services:
backend:
command: node app.js
networks:
app_net:
ipv4_address: 172.18.0.2
nginx:
build: ./nginx
ports:
- "80:80"
networks:
- app_net
networks:
app_net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.18.0.0/16
gateway: 172.18.0.1 Now restarting the backend doesn't require restarting Nginx as well. Hoping for a nicer pattern in the future! |
If anyone later stumbles on this issue, as I did, trying to fix container restarts with docker-compose: as of v1.1.9, nginx now offers a This is not exactly "dynamic resolution" but it's close enough. |
Restarting a Docker service can change the service's IP address. However, Nginx will not perform DNS resolution again, so using a static IP address can avoid this problem. docker/compose#3314
Restarting a Docker service can change the service's IP address. However, Nginx will not perform DNS resolution again, so using a static IP address can avoid this problem. docker/compose#3314
I am using Compose 1.7.0-rc2 and the V2 compose file format. No explicit network defined, just the default networking.
I have a backend container running Node.js and an Nginx container set up to proxy_pass requests to the backend container.
This all works fine except if I restart the backend container. Then it seems the backend's IP changes, but Nginx continues to use the old IP.
I have gone down the rabbit hole of trying to figure out how to get Nginx to resolve the IP dynamically, but the complexity skyrockets quickly, and nothing specific to V2 compose files has apparently been written.
Is there a simple and up-to-date way of accomplishing this apparently monumental task?
The text was updated successfully, but these errors were encountered: