nginx-proxy

nginx-proxy is a tool that can be defined as “Automated nginx proxy for Docker containers using docker-gen. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped.”. I used nginx-proxy for generating random subdomains for recently spawned docker containers.

I’m developing a data annotation tool for our team. We decided to spawn a container for each annotator. After that, we needed unique and shuffled URLs that anyone should not access by brute-forcing.

After a few quick searches, I came across Traefik. It might be good to use that tool with lots of capabilities and definitely solves my problem. However, I didn’t have time to learn something big and new. Then, I found a blog post, “Automated Nginx Reverse Proxy for Docker”, that tells what I want is easily applicable by nginx-proxy. I’m cutting my story in here and letting the code itself talks.

Nginx-proxy has the following features:

  • IPv6 support
  • Multiple ports
  • Wildcard hosts
  • Multiple networks
  • SSL support
  • Basic authentication support
  • … and more.

All you need to do is as simple as the following:

  1. First, run nginx-proxy container.
    • docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
  2. Then, run any container you want with -e VIRTUAL_HOST=”” flag.
    • docker run -e VIRTUAL_HOST=foo.bar.com …(rest of the params)

That’s it.

References:

  1. nginx-proxy, https://github.com/nginx-proxy/nginx-proxy
  2. docker-gen, https://github.com/jwilder/docker-gen
  3. Traefik, https://docs.traefik.io/
  4. Automated Nginx Reverse Proxy for Docker, http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/

Leave a Reply

Your email address will not be published. Required fields are marked *