Automate reverse proxying in Docker

The problem

I've recently started my journey into Docker. At the same time I'm continuining my journey into Node.js, Angular and as usual a bunch of other stuff.

I've had a little raspberry pi box sat around for a little while, wondering how I should use it.

I decided to 'containerise' my new Node.js apps and make them accessible to the web. The only problem being that I had a number of apps which were exposed on different port numbers on the same host and needed to be served to different subdomains.

Initially, I setup NGINX as a reverse proxy inside a container with the Lets Encrypt client...

It was horrible, it was an embarrassing mess. Every time I wanted to add a new project to the reverse proxy I'd have to rebuild the image and add a load of configuration.

I know I could've made it much smoother, but I had no interest in making the 'perfect' reverse proxy configuration setup.

The solution

Træfik.

I couldn't believe it.

After all of the effort I put into getting a homemade basic reverse proxy with TLS (https) to work. And Traefik just works!

I added it to my docker-compose.yml as it suggests and off we go!

It automatically picks up which containers are running and determines the hostnames and routing rules from labels added to the service/containers.

It provides the HTTPS, it does the proxying and it does the load balancing (not really needed on my Pi - but I tested it anyway!).

traefik-frontend
traefik-backend

comments powered by Disqus