1

How do we get NGINX reverse proxy to proxy_pass into the right IP/resolve the container's hostname? I get the notion that resolver pointing to an exposed Docker-embedded DNS is ideal.

Context: Debian Host (not dockerized) NGINX. Docker containers are on same host and necessarily on an overlay network and working well in their own right.

I've been experimenting & reading for hours on this and similar posts include:

https://stackoverflow.com/questions/35744650/docker-network-nginx-resolver

https://stackoverflow.com/questions/39729663/query-docker-embedded-dns-from-host

I was unable to get nslookup to work with Consul and various DNSmasq stuff

socat approach nearly got me there, but it resolves and spits out the non-exposed (non-overlay) network IP

Malachi
  • 171
  • 1
  • 1
  • 6
  • 1
    Have a look at [jwilder automatic nginx proxy for docker](https://github.com/jwilder/nginx-proxy). There now other products offering the same kind of service (and much more... like [traefik](https://github.com/containous/traefik)), but jwilder implementation is simple and easy to study to understand how things are done. – Zeitounator Jan 04 '20 at 11:41
  • Quite interesting -- especially the `docker-gen` part! – Malachi Jan 06 '20 at 08:14

1 Answers1

1

What are you trying to achieve? As far as I know, when running a docker container you should open its ports on the docker host. This way the nginx proxy configuration can point to the desired port on the local address (localhost/127.0.0.1).

For example I would run: docker run -p 8080:8080 myapp

Then configure Nginx with:

location / {
    proxy_pass http://127.0.0.1:8080;
    ... other desired options ...
}
  • My use case originally was containers were floating on a network, possibly DHCP'd, with nginx proxy elsewhere – Malachi Jan 06 '20 at 08:13