What you need

You need a server with Docker and Docker Compose. For HTTPS, point a domain to the server IP, for example demo.example.com.

1. Create a project folder

mkdir traefik-sample
cd traefik-sample
mkdir letsencrypt

2. Create the Docker Compose file

The sample page uses the official traefik/whoami container. It prints request information, which makes it useful for testing Traefik routing.

services:
  traefik:
    image: traefik:v3.0
    command:
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --certificatesresolvers.letsencrypt.acme.email=admin@example.com
      - --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
      - --certificatesresolvers.letsencrypt.acme.httpchallenge=true
      - --certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./letsencrypt:/letsencrypt
    restart: unless-stopped

  sample:
    image: traefik/whoami:v1.10
    labels:
      - traefik.enable=true
      - traefik.http.routers.sample.rule=Host(`demo.example.com`)
      - traefik.http.routers.sample.entrypoints=websecure
      - traefik.http.routers.sample.tls.certresolver=letsencrypt
      - traefik.http.services.sample.loadbalancer.server.port=80
    restart: unless-stopped

Replace admin@example.com with your email address and demo.example.com with your real domain.

3. Start it

docker compose up -d

Then open https://demo.example.com. If DNS, firewall rules and ports are correct, you will see the Whoami output.

4. Common errors

  • Port 80 or 443 is already used by nginx, Apache or another container.
  • The domain does not point to the correct server IP yet.
  • The firewall blocks incoming HTTP or HTTPS traffic.
  • The Docker socket volume is missing, so Traefik cannot read container labels.

5. Next step

Once the sample page works, replace the sample service with your real app. The important parts are traefik.enable=true, the Host rule and the correct internal container port.