This is the docker compose and configuration for an instance of Traefik v2.3.2
You can find a quick draft for v1.7 configuration on an older commit
- HTTP redirect to HTTPS
- Let's Encrypt auto-generated certificates via HTTP challenge
Be careful as the Traefik dashboard is configured as insecure. You can comment line 20 of traefic.toml to prevent this behavior
- Clone the repository
- Uncomment and replace <mail> in traefik.toml by your email for Let's Encrypt
- Create an empty "acme.json" file at the base of this folder. Then set the correct permissions.
touch acme.json & chmod 600 acme.json
Let's Encrypt is requiring an acme.json file to store certificates. Click here to know more
- Add these labels to your docker compose service and Traefik will automatically add them.
Don't forget to replace:- <domain name> by the domain name of the service
- <service> by your service name
- <port> by the service's port you want Traefik to redirect to (optional)
...
<service>:
...
labels:
- traefik.http.routers.<service>.rule=Host("<domain name>")
- traefik.http.services.<service>.loadbalancer.server.port=<port>
- traefik.http.routers.<service>.tls=true
- traefik.http.routers.<service>.tls.certresolver=letsencrypt
- traefik.http.routers.<service>.entrypoints=web-secure
- traefik.enable=true
...
Required labels:
Redirect incoming requests to <domain name>. Details on Traefik rules here
traefik.http.routers.<service>.rule=Host("<domain name>")
Enable tls on the service:
traefik.http.routers.<service>.tls=true
Use certresolver letsencrypt configured in traefik.toml:
traefik.http.routers.<service>.tls.certresolver=letsencrypt
Accept requests from web-secure entrypoint only:
traefik.http.routers.<service>.entrypoints=web-secure
More info here:
traefik.enable=true
Optional labels:
Redirect incoming traffic to port <port> of the service:
traefik.http.services.<service>.loadbalancer.server.port=<port>
-
Create an docker network with this command:
docker network create web
-
Add this at the end of your docker-compose file (you have to add it for every different docker-compose file)
...
networks:
web:
external: true
- Add the service to the network:
...
<service>:
...
networks:
web:
...
The network web enable traefik instance to communicate with other services from different docker-composes
- Once everything is done, launch the traefik instance from traefik-config folder.
docker-compose up