Traefik docker-compose stack for local development usage with HTTPS
First, you need to install mkcert to generate your local certificates. See mkcert#Installation
Then, install the mkcert root CA
$ mkcert -install
Generates certificates for your local domain
$ mkcert -key-file certs/key.pem -cert-file certs/cert.pem domain.local \*.domain.local
Create traefik docker network
$ docker network create traefik
Create and start the docker-compose stack
$ docker-compose up -d
Your local traefik is now up and ready! You can access to dashboard at http://localhost:8080
In order to plug a container to traefik reverse proxy, you need to use docker labels. There is an example with a whoami docker-compose stack.
version: '3'
services:
whoami:
image: 'containous/whoami'
networks:
- traefik
labels:
# expose container to traefik
- traefik.enable=true
# set up http host
- traefik.http.routers.whoami-http.rule=Host(`whoami.domain.local`)
- traefik.http.routers.whoami-http.entrypoints=http
# set up middleware to redirect http to https
- traefik.http.routers.whoami-http.middlewares=redirect-to-https@file
# set up https host
- traefik.http.routers.whoami-https.rule=Host(`whoami.domain.local`)
- traefik.http.routers.whoami-https.entrypoints=https
- traefik.http.routers.whoami-https.tls=true
networks:
traefik:
name: traefik
external: true
Don't forget to add your local domain into your /etc/hosts file!
Now, you're be able to access whoami at https://whoami.domain.local under https!