🖥 Infrastructure

Installer et configurer Traefik v3 avec Docker Rootless

📅 18 juin 202515 min de lecture
traefikdockernginxssl

Architecture

Internet
  Port 80 redirection HTTPS
  Port 443
  Traefik v3
    ├── traefik.ignis.fr Dashboard
    ├── ignis-fox.fr Stack Ignis (Nginx)
    └── autre.ignis.fr Autre service

Traefik surveille les conteneurs Docker via le socket Docker. Quand un conteneur démarre avec les bons labels, la route est créée automatiquement.

Autoriser les ports 80/443 en rootless

echo 'net.ipv4.ip_unprivileged_port_start=80' | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
✅ Vérification
sysctl net.ipv4.ip_unprivileged_port_start
# net.ipv4.ip_unprivileged_port_start = 80

Structure de dossiers

sudo -i -u admin_docker
mkdir -p /opt/docker-data/proxy/{config/dynamic,certs,logs}
/opt/docker-data/proxy/
├── config/
   ├── traefik.yml
   └── dynamic/
       ├── certificates.yml
       └── middlewares.yml
├── certs/
└── logs/

traefik.yml — Configuration statique

api:
  dashboard: true
  insecure: false
 
entryPoints:
  web:
    address: ":80"
    http:
      redirections:
        entrypoint:
          to: websecure
          scheme: https
          permanent: true
  websecure:
    address: ":443"
 
providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
    watch: true
  file:
    directory: /opt/docker-data/proxy/config/dynamic
    watch: true
 
log:
  level: INFO
  filePath: "/logs/traefik.log"
 
accessLog:
  filePath: "/logs/access.log"

Socket dans traefik.yml Le chemin unix:///var/run/docker.sock est le chemin dans le conteneur, pas sur l'hôte. Le socket hôte est monté via le volume.

certificates.yml

tls:
  certificates:
    - certFile: /certs/docker-ignis.crt
      keyFile: /certs/docker-ignis.key
      stores:
        - default

middlewares.yml

http:
  middlewares:
    redirect-to-https:
      redirectScheme:
        scheme: https
        permanent: true
    security-headers:
      headers:
        customResponseHeaders:
          X-Robots-Tag: "none"
          server: ""
        stsSeconds: 31536000
        stsIncludeSubdomains: true
        forceSTSHeader: true
        frameDeny: true
        contentTypeNosniff: true

Référencer un middleware Dans les labels Docker : "traefik.http.routers.monapp.middlewares=security-headers@file"

Docker Compose

services:
  traefik:
    image: traefik:v3.6.10
    container_name: traefik
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /run/user/1002/docker.sock:/var/run/docker.sock:ro
      - ./config/traefik.yml:/traefik.yml:ro
      - ./config/dynamic:/opt/docker-data/proxy/config/dynamic:ro
      - ./certs:/certs:ro
      - ./logs:/logs:rw
    networks:
      - traefik-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dashboard-secure.rule=Host(`traefik.ignis.fr`)"
      - "traefik.http.routers.dashboard-secure.entrypoints=websecure"
      - "traefik.http.routers.dashboard-secure.tls=true"
      - "traefik.http.routers.dashboard-secure.service=api@internal"
      - "traefik.http.routers.dashboard-secure.middlewares=security-headers@file"
 
networks:
  traefik-network:
    external: true

Socket en chemin absolu Utiliser /run/user/1002/docker.sock plutôt que ${{XDG_RUNTIME_DIR}}/docker.sock qui peut être vide hors session interactive.

DNS local Windows

Ouvrez Notepad en administrateur et éditez C:\Windows\System32\drivers\etc\hosts :

127.0.0.1   traefik.ignis.fr
127.0.0.1   ignis-fox.fr

Démarrage

cd /opt/docker-data/proxy
docker compose up -d
 
# Lire les logs (docker logs sera vide)
tail -f /opt/docker-data/proxy/logs/traefik.log
✅ Vérification

Ouvrir https://traefik.ignis.fr — le dashboard doit s'afficher avec le cadenas HTTPS vert.

Ajouter un service

services:
  monapp:
    image: mon-image
    networks:
      - traefik-network
      - ignis-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.monapp.rule=Host(`monapp.ignis.fr`)"
      - "traefik.http.routers.monapp.entrypoints=websecure"
      - "traefik.http.routers.monapp.tls=true"
      - "traefik.http.routers.monapp.middlewares=security-headers@file"
      - "traefik.http.services.monapp.loadbalancer.server.port=3000"

Erreurs fréquentes

ErreurCauseSolution
bind: permission deniedPort bas non autoriséAjouter net.ipv4.ip_unprivileged_port_start=80
Cannot connect to daemonMauvais chemin socketVérifier /run/user/1002/docker.sock
Logs videsLogs dans des fichierstail -f /opt/docker-data/proxy/logs/traefik.log
Dashboard inaccessibleDNS local manquantAjouter dans le fichier hosts Windows
Certificat non reconnuCA pas installéeVoir article SSL section 7