nginx-proxy: nginx.conf does not get updated with overlay network IPs
I created an overlay-network for my swarm and can ping and wget a hello-world webserver in the swarm from the reverseproxy container.
This is my /etc/hosts
10.0.1.7 mynetwork_hello_1
And this the relevant part of nginx.conf
upstream ~my.test.com {
# mynetwork_hello_1
server :80;
}
As you can see the IP is missing.
Looks like somewhere around here the IP does not get written correctly.
Any idea how to fix this or is this an issue with docker-gen?
Tested on: docker 1.9.1, docker-compose 1.5.1
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 17
- Comments: 66 (12 by maintainers)
Commits related to this issue
- quickfix for https://github.com/jwilder/nginx-proxy/issues/304 — committed to sutyrin/nginx-proxy by sutyrin 8 years ago
- added basic docker 1.9 networking support — committed to nginx-proxy/docker-gen by schmunk42 9 years ago
- update fetch template to be compatible with docker networking used by compose v2 files * https://github.com/jwilder/nginx-proxy/issues/304#issuecomment-189775983 — committed to ecobytes/docker-nginx-gen-letsencrypt by almereyda 8 years ago
- Because of https://github.com/jwilder/nginx-proxy/issues/304, right now docker-compose.prod.yml is ported back to version 1 — committed to SpisTresci/scrooge by noisy 8 years ago
- Because of https://github.com/jwilder/nginx-proxy/issues/304, right now docker-compose.prod.yml is ported back to version 1 — committed to SpisTresci/scrooge by noisy 8 years ago
- Because of https://github.com/jwilder/nginx-proxy/issues/304, right now docker-compose.prod.yml is ported back to version 1 — committed to SpisTresci/scrooge by noisy 8 years ago
- Revert "Because of https://github.com/jwilder/nginx-proxy/issues/304, right now docker-compose.prod.yml is ported back to version 1" This reverts commit 0b2cfa53c6ea48c6f24792fcdbc164cb441a9dff. — committed to noisy/SpisTresci by noisy 8 years ago
- Revert "Because of https://github.com/jwilder/nginx-proxy/issues/304, right now docker-compose.prod.yml is ported back to version 1" This reverts commit 0b2cfa53c6ea48c6f24792fcdbc164cb441a9dff. — committed to noisy/SpisTresci by noisy 8 years ago
- Revert "Because of https://github.com/jwilder/nginx-proxy/issues/304, right now docker-compose.prod.yml is ported back to version 1" This reverts commit 0b2cfa53c6ea48c6f24792fcdbc164cb441a9dff. — committed to noisy/SpisTresci by noisy 8 years ago
- Fix issue of auto-discovery when using compose v2 syntax Ref: https://github.com/jwilder/nginx-proxy/issues/304 — committed to SteveLTN/https-portal by SteveLTN 7 years ago
What’s the status on this issue?
#425 was closed and #337 was merged
@wader @Ant59 @meyer Just in case, it isn’t necessary to downgrade to version 1 compose file, just add
network_mode: bridgeto each service instead (which is the old default).Hey,
Not sure this is the right place for this, but i think if you’re gonna do it through compose, you should re-declare the entrypoint. If you look at the Dockerfile, you can see it’s meant to receive arguments.
Since you’re trying to run nginx-proxy using separate containers, you have to give the nginx container a name and feed it to docker-gen so that it knows which container to send signals.
This part of your compose file cannot work:
- /etc/docker-gen/templates/nginx.tmpl:/etc/nginx/conf.d/default.confIt is docker-gen, that is going to use nginx.tmpl and generate default.conf for nginx to use. What you’re doing here is simply mounting nginx.tmpl as default.conf as is and nginx will never understand it.
I would also advise to use compose v2, even though this thread is about the problems it may cause, it has already provided a solution that works. This way you won’t get any bad surprises when v1 becomes legacy.
Here’s what a a docker-compose.yml could look like:
This of course will not work as is. If you want a complete working example, have a look here
Like i said this is compose v2, with the revamped network support. So you’ll want to create a host-wide (or swarm-wide through overlay) network first for your nginx-proxy container that will be configured by docker-gen to connect with your other nginx that will serve your sites (Unless you want to expose a new unique port for every site)
$ docker network create -d bridge nginx-proxyI’d recommend using @almereyda ‘s upstream block (earlier in this thread), and have your sites’ compose files look something like this:
Hope this helps.
I am now also using the following declaration to get working results:
@mickaelperrin did you solve it? I am using nginx,nginx-gen and companion and I have no host…
FWIW, I got it to work using rckrdstrgrd/nginx-proxy in my config here: https://github.com/duck1123/jiksnu/blob/feature/cucumber/docker-compose.yml
I feel that the issue has been resolve. It just needs to be merged from @duck1123.
Cheers! Pascal
The
READMEshould be updated accordingly (it refers to this issue).@Nepoxx looks like this has not beed published on docker hub yet
I’ve tested the changes from #425 and it works like a charm xD nginx-proxy
👍 same problem here with docker 1.10 and latest nginx-proxy
@pascalandy
Glad it could be useful!
As for your compose file, it’s actually much more simple now with the new docker networks. You can remove the
portion of your files altogether. You nginx-proxy container and sites will be on the same network, no need to expose ports, just listen on your ghost instances and define the VIRTUAL_PORT and you’ll be good to go.
As for the first part of your message, i didn’t get what you use docker run for and why it’s the same command twice.
Have a look at this gist for an extensive example for Nginx + PHP + MySQL. To add SSL, you’d just need to add
I found a much better solution for the v2 Compose file breakage on container restart: in my derivative image with the v2 template tweaks, I also save a copy of the original
/etc/nginx/conf.d/default.confto/appand re-copy it back on container startup in the entrypoint.Before this change, nginx would read the stale config file and bail when it couldn’t find an old container’s upstream host (which might not have come back up yet, or might not be coming back at all).
After the change, nginx is happy to read the original config file and gets signaled by docker-gen when other containers have come up and the new config is ready.
Here’s my
Dockerfile:And my
docker-entrypoint.sh:The
nginx.tmplincludes the changes @almereyda provided above.Yes, the previous comment.