9

After upgrading to Docker engine 1.10 (from 1.08) I've noticed that my reverse proxy configuration is not working anymore.

All my apps (including Nginx for reverse proxies) are containerized and were communicating via container names. Here's an example for virtual hosts part in Nginx:

server {
    server_name jobs;
    location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://jenkins:8080;
    }
}

Now, I can ping Jenkins container from Nginx container only via IP but not anymore via container name. As IPs are constantly changed due to updates, redeployments, etc. is there a better networking way of avoiding defining IPs in reverse proxy configuration?

Legacy --link is not an option as there are lots of containers.

Edgaras
  • 93
  • 1
  • 4
  • I have updated the answer in light of the upcoming docker 1.12 and its docker swarm mode. – VonC Jul 14 '16 at 20:32

1 Answers1

2

You can check the network-scope alias which comes with docker network connect and docker run.

Starting a container with an alias allows your NGinx to reverse proxy to that alias in its config.
At runtime, that alias will resolve to the container that you started later.

See an example in "Docker Networking: Auto-discovering host names in a bridge network".
Note that you will need a key-value store to manage your container in a docker 1.10+ network.


Note (July 2016) with docker 1.12 and its swarm mode, it becomes even simpler.
See for instance "The beautiful networking stack in Docker Swarm mode"

The docker swarm will define an overlay network and a key-value store for you! The containers will see each others.

Another concrete example: "NGINX as a Reverse Proxy for Docker Swarm Clusters"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250