DEV Community

Cover image for Easy and powerful reverse proxy and load balancing with Docker
Stephen Afam-Osemene
Stephen Afam-Osemene

Posted on

Easy and powerful reverse proxy and load balancing with Docker

I build a lot of websites, and I run them in Docker containers. What happens is, I end up with URLs like this 0.0.0.0:1234.

This is a problem because,

  1. They are difficult to remember
  2. Do not allow sub-domains.
  3. Bad for password managers

My initial solution was to add a reverse proxy with Nginx so I have virtual hosts that point to my containers. However, this means I was writing the same Nginx configuration, over and over again, only with different ports.

So as any sane developer will do, I took a couple hours to automate the process once and for all.

let's do this

The solution

I ended up creating a docker image to generate my configuration files and be a proper reverse proxy.
You can find it here

Features

  1. Sets up reverse proxies with just a few lines of configuration
  2. Can automatically obtain SSL certificates from let's encrypt
  3. Can be used to set up load balancing between several servers
  4. Allows fine tuning of the load balancing configuration.

I'll add more features as I discover more use cases. Let me know if there is anything

Proper details on how to use are in the README.md of the repository.
If you like it, star on GitHub.

Top comments (5)

Collapse
 
benhemphill profile image
Ben Hemphill • Edited

I would agree with the other's suggestion that you should look into Traefik. I personally favor Kubernetes as the backend for that, but Swarm is likely already installed if you are on a recent version of docker and is supported too. That all being said, I enjoyed your approach and write up. I bet you learned a good amount from this project, and that is never a bad thing!

Collapse
 
glego profile image
Glenn Goffin

Good job Stephen, well documented and very clean written scripts. Thanks for sharing.

Collapse
 
psyhomb profile image
Miloš Bunčić

Yeah Traefik is definitely a good choice for these kind of things, I used it myself in a similar fashion in one of my projects github.com/psyhomb/k8s-deployer

Anyway good work!

Collapse
 
denis_lt profile image
Denis

Why didn't you use Traefik?

Collapse
 
stephenafamo profile image
Stephen Afam-Osemene

Just hearing about it. I'll check it out.