PortGate

Blueprints · Reverse Proxy & SSL

Production 30 min · Traefik / Docker

Traefik v3 Docker reverse proxy, certificates, and middleware

Runs Traefik against a filtered Docker socket proxy, requests certificates for the site, adds secure headers, and puts basic auth plus an IP allowlist on the dashboard.

Live config

Baked-in protections

Step 1 · yaml

Compose file

/opt/traefik/compose.yaml

Generate DASHBOARD_HASH with htpasswd -nbB. POST is off on the socket proxy so a container cannot create privileged containers through it.

services:
  socket-proxy:
    image: tecnativa/docker-socket-proxy:latest
    environment:
      CONTAINERS: 1
      SERVICES: 1
      NETWORKS: 1
      TASKS: 1
      POST: 0
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports:
      - "127.0.0.1:2375:2375"
    read_only: true
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped
  traefik:
    image: traefik:v3
    depends_on:
      - socket-proxy
    command:
      - --providers.docker.endpoint=tcp://socket-proxy:2375
      - --providers.docker.exposedbydefault=false
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - [email protected]
      - --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
      - --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
      - --api.dashboard=true
    ports:
      - "80:80"
      - "443:443"
      - "127.0.0.1:8080:8080"
    volumes:
      - traefik-certs:/letsencrypt
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped
volumes:
  traefik-certs:

Step 2 · yaml

Dynamic middleware

/opt/traefik/dynamic.yml

Attach this file with a file provider, or merge the labels onto the app service. The dashboard allowlist is the admin CIDR.

http:
  middlewares:
    secure-headers:
      headers:
        stsSeconds: 31536000
        stsIncludeSubdomains: true
        contentTypeNosniff: true
        frameDeny: true
        referrerPolicy: strict-origin-when-cross-origin
        customResponseHeaders:
          Server: ""
    dashboard-auth:
      basicAuth:
        users:
          - "admin:$apr1$change$me"
    dashboard-allow:
      ipAllowList:
        sourceRange:
          - "203.0.113.10/32"
          - "127.0.0.1/32"
  routers:
    app:
      rule: Host(`app.example.com`)
      entryPoints: [websecure]
      middlewares: [secure-headers]
      service: app
      tls:
        certResolver: le
    dashboard:
      rule: Host(`traefik.app.example.com`)
      entryPoints: [websecure]
      middlewares: [dashboard-auth, dashboard-allow]
      service: api@internal
      tls:
        certResolver: le
  services:
    app:
      loadBalancer:
        servers:
          - url: http://127.0.0.1:8080