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 to each annotator. After that, we needed unique and shuffled URLs that anyone should not access by brute forcing.

After few quick searches, I came across with 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 let the code itself talks.

Nginx-proxy has 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 following:

  • First, run nginx-proxy container.
COMMAND
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
  • Then, run any container you want with -e VIRTUAL_HOST=”” flag.
COMMAND
docker run -e VIRTUAL_HOST=foo.bar.com …

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 *