using traefik

2026-04-30

since im provisioning a new VPS, i feel like i want to try something new rather than using the same old plain nginx. this time, i stumbled upon traefik, and upon looking the docs i wanted to try it since all i do is deploy docker containers.


the catch is really simple, all you need is to spin up a traefik container using this docker compose

services:
traefik:
image: traefik:v3
container_name: traefik
restart: unless-stopped
command:
- --api.dashboard=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --certificatesresolvers.letsencrypt.acme.tlschallenge=true
- --certificatesresolvers.letsencrypt.acme.email=endra.rocks@gmail.com
- --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
labels:
- "traefik.enable=true"
- "traefik.http.routers.dashboard.rule=Host(`yourapp.com`)"
- "traefik.http.routers.dashboard.entrypoints=websecure"
- "traefik.http.routers.dashboard.tls.certresolver=letsencrypt"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.middlewares=dashboard-auth"
- "traefik.http.middlewares.dashboard-auth.basicauth.users=admin:$$2y$$05$$xjO2xdnw5URPNFa0kXiJuuqt5qkqs8CgCIUYlKcWt0WsG5ithTc86"
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- letsencrypt:/letsencrypt
networks:
- traefik-public
volumes:
letsencrypt:
networks:
traefik-public:
external: true


you noticed that we created a new networks right? the traefik-public one, that what we will be using so that traefik could “locate” our services.

if that is done, all we need is to add some new labels and network to our existing container

labels:
- "traefik.enable=true"
- "traefik.http.routers.app.rule=Host(`yourapp.com`)"
- "traefik.http.routers.app.entrypoints=websecure"
- "traefik.http.routers.app.tls.certresolver=letsencrypt"
- "traefik.http.services.app.loadbalancer.server.port=3000"
networks:
- default
- traefik-public
networks:
traefik-public:
external: true


thats all we need to connect our container to the traefik for reverse proxy, just define the url of the app and dont forget to point an A type of DNS to your vps ip and voila, everything is set up. no need to run sudo sytemctl nginx reload everytime you set up a new site, no need to remember where and how you link your files from enabled to available. all you need is ole simple labels.