Search code examples
nginxcontainersibm-cloudload-balancingdocker-compose

How can I use nginx as a dynamic load balancing proxy server on Bluemix?


I am using docker-compose to run an application on the bluemix container service. I am using nginx as a proxy webserver and load balancer.

I have found an image that uses docker events to automatically detect new web servers and adds those to the nginx configuration dynamically:

https://github.com/jwilder/nginx-proxy

But for this to work, I think the container needs to connect to a docker socket. I am not very familiar with docker and I dont know exactly what this does, but essentially it is necessary so that the image can listen to docker events.

The run command from the image documentation is the following:

docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

I have not been able to run this in the container service, as it does not find the /var/run/docker.sock file on the host.

The bluemix documentation has a tutorial explaining how to do load balancing with nginx. But it requires a "hard coded" list of web servers in the nginx configuration.

I was wondering how I could run the nginx-proxy image so that web instances are detected automatically?


Solution

  • The containers service on Bluemix doesn't expose that docker socket (not surprising, it would be a security risk to the compute host). A couple of alternate ways to accomplish what you want:

    • something like amalgam8 or consul, which is basically doing just that
    • similar, but self written - have a shared volume, and then each container on startup adds a file to that shared volume saying what it is, plus its private ip. nginx container has a watch on the shared volume, and reloads when those change. (more work than amalgam8 or consul, but perhaps more control)