You have to secure your websites with SSL!

How to setup Traefik v2 with automatic Let’s Encrypt certificate resolver

Today it is really important to have SSL encrypted websites. This guide will show how easy it is to have an automatic SSL resolver built into your traefik load balancer.

Paul Knulst
Published in
3 min readNov 30, 2021

--

Illustration of components used to achieve the goal

After I learned how to docker, the next thing I needed was a service to help me organize my websites. This is why I learned about traefik which is a:

Cloud-Native Networking Stack That Just Works

One important feature of traefik is the ability to create Let’s Encrypt SSL certificates automatically for every domain which is managed by traefik.

Then I started to research…

Me sitting in front of my computer researching
Me sitting in front of my computer researching

I tested several configurations and created my own traefik instances on my local machine until I came up with this docker-compose.yml:

This file contains several important sections:

  1. Two entry points web (Line 8) and websecure (Line 9) which are used for http and https
  2. Enabling docker (Line 10) but not publishing every container by default (Line 11)
  3. Activate API (with URL defined in labels) (Line 12)
  4. Certificate handling. Defining an info email (Line 13), set a storage acme.json (Line 14), activating TLS (Line 15)
  5. Exposing port for HTTP (Line 17) and HTTPS (Line 18)
  6. Within the volumes section, the docker-socket will be mounted into traefik container (Line 20) and the acme.json is mounted into the local filesystem (Line 21)
  7. Enable traefik for this service (Line 23). This has to be done because no service is exported by default (see

--

--

Husband, father of two, geek, lifelong learner, tech lover & software engineer. Writing about projects and challenges in IT. https://www.paulsblog.dev