🐳
blog.cat.ssl

Automatic SSL in Docker with Traefik: A Complete Setup

22.11.2026
← All articles

When several services run in Docker on one server, getting and renewing an SSL certificate for each one quickly becomes tedious: a new Nginx config per container, a Certbot run, and a reload you must not forget. Traefik automates all of it. It watches your containers, reads from their labels which domain belongs to which container, and obtains and renews Let's Encrypt certificates on its own. This article builds a complete working setup for Traefik 3.

How Traefik works

Traefik is a reverse proxy that reads its configuration from Docker. Through the Docker socket it sees containers start, reads their labels and creates routes: which hostname, which entry point and which certificate resolver. A certificate resolver describes how to get certificates over ACME: which CA, which challenge type and where to store them. Adding a service never requires touching Traefik itself, only labelling the container.

Preparation

Every hostname, such as example.uz and www.example.uz, must resolve to your server, and ports 80 and 443 must be open and not used by another program such as an old Nginx install. The HTTP challenge uses port 80, so closing it in the firewall stops issuance. For domains registered with sayt.uz, A records are added in the DNS section of the cabinet.

A complete docker-compose.yml

Traefik opens web on 80 and websecure on 443, redirects all HTTP to HTTPS, and the le resolver obtains certificates via the HTTP challenge, storing them in acme.json.

services:
  traefik:
    image: traefik:v3
    command:
      - --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.le.acme.email=admin@example.uz
      - --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
      - --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./letsencrypt:/letsencrypt
    restart: unless-stopped

  site:
    image: nginx:alpine
    labels:
      - traefik.enable=true
      - traefik.http.routers.site.rule=Host(`example.uz`) || Host(`www.example.uz`)
      - traefik.http.routers.site.entrypoints=websecure
      - traefik.http.routers.site.tls.certresolver=le
      - traefik.http.services.site.loadbalancer.server.port=80
    restart: unless-stopped

With exposedbydefault=false, only containers labelled traefik.enable=true are published, so an internal database is never exposed by accident. loadbalancer.server.port is the port inside the container and does not need a ports mapping.

mkdir -p letsencrypt
docker compose up -d
docker compose logs -f traefik

Test against staging first

Let's Encrypt limits failed attempts, and retry loops caused by DNS or port mistakes can lock you out temporarily. Add the staging CA while testing:

      - --certificatesresolvers.le.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory

Staging certificates show as untrusted, which is expected. Once everything works, remove the line, delete letsencrypt/acme.json and restart, otherwise Traefik keeps serving the stored test certificates.

Example: a training centre site and CRM

A private training centre in Namangan runs its public site misol.uz and an internal student CRM at crm.misol.uz in Docker on a VPS. Previously each had its own Nginx config and Certbot command, and once the CRM certificate failed to renew, locking managers out one morning. After moving to Traefik, the CRM needed only this block and got its certificate on first start:

  crm:
    image: misol/crm:latest
    labels:
      - traefik.enable=true
      - traefik.http.routers.crm.rule=Host(`crm.misol.uz`)
      - traefik.http.routers.crm.entrypoints=websecure
      - traefik.http.routers.crm.tls.certresolver=le
      - traefik.http.services.crm.loadbalancer.server.port=3000
    restart: unless-stopped

Adding a service now takes four labels and docker compose up -d, and Traefik renews certificates well before they expire.

Wildcards and the DNS challenge

A wildcard such as *.example.uz requires DNS-01. Traefik supports it if your DNS provider has an API and appears in Traefik's provider list; the docs list the environment variables for each.

Security: the Docker socket and acme.json

Access to the Docker socket is effectively root on the host, and :ro does not restrict API calls. Never expose the Traefik dashboard without authentication, and consider a socket proxy that only allows read requests. acme.json holds every private key: back it up, but never commit it to a public repository.

Verifying

If no certificate appears, read the ACME messages in the Traefik logs; they usually name the cause, such as wrong DNS, a closed port 80 or a rate limit.

docker compose logs traefik 2>&1 | grep -i acme
openssl s_client -connect example.uz:443 -servername example.uz </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates

Related articles

🔑 Lost or leaked SSL private key: what to do 🔍 CT Logs Reveal Your Subdomains: The Risk of "Hidden" Test Sites ✳️ Automating wildcard SSL with DNS-01: a Certbot and acme.sh guide 🪪 Client Certificate Login: An Extra Lock for Your Admin Panel
🌐 Language
🇺🇿 O⁠'zbek 🇺🇿 Özbek (yangi) 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓