webjocky

Working Traefik 2.X Example

May 18th, 2021
828
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. version: '3.8'
  2.  
  3. x-default-opts:
  4.   &default-opts
  5.   logging:
  6.     options:
  7.       max-size: "1m"
  8.  
  9. services:
  10.   proxy:
  11.     <<: *default-opts
  12.     depends_on:
  13.      - dockersocket
  14.     image: traefik:latest
  15.     volumes:
  16.      - /local/path/to/logs:/logs
  17.     environment:
  18.       TZ: "US/New York"
  19.     command:
  20.      - "--providers.docker"
  21.       - "--providers.docker.exposedByDefault=false"
  22.       - "--providers.docker.endpoint=tcp://dockersocket:2375"
  23.       - "--providers.docker.swarmMode=true"
  24.       - "--providers.docker.network=traefik-public"
  25.  
  26.       - "--log=true"
  27.       - "--log.filePath=/logs/traefik.log"
  28.       - "--log.level=ERROR"
  29.       - "--accesslog=true"
  30.       - "--accesslog.filepath=/logs/access.log"
  31.       - "--accesslog.bufferingsize=25"
  32.       - "--api=true"
  33.       - "--api.dashboard=true"
  34.       - "--api.insecure=true"
  35.  
  36.       - "--entryPoints.http.address=:80"
  37.       - "--entryPoints.https.address=:443"
  38.  
  39.     ports:
  40.       - target: 80
  41.         published: 80
  42.         protocol: tcp
  43.         mode: host
  44.       - target: 443
  45.         published: 443
  46.         protocol: tcp
  47.         mode: host
  48.  
  49.     deploy:
  50.       mode: global
  51.       placement:
  52.         constraints:
  53.          - "node.role==manager"
  54.       labels:
  55.         traefik.enable: "true"
  56.         traefik.http.routers.api.entrypoints: "http"
  57.         traefik.http.routers.api.rule: "Host(`*`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))"
  58.         traefik.http.routers.api.service: "api@internal"
  59.         traefik.http.services.api.loadbalancer.server.port: "8080"
  60.     networks:
  61.      - traefik-socket
  62.       - traefik-public
  63.  
  64.   dockersocket:
  65.     <<: *default-opts
  66.     image: tecnativa/docker-socket-proxy
  67.     volumes:
  68.      - /var/run/docker.sock:/var/run/docker.sock
  69.     environment:
  70.       CONTAINERS: 1
  71.       NETWORKS: 1
  72.       SERVICES: 1
  73.       SWARM: 1
  74.       TASKS: 1
  75.     deploy:
  76.       mode: global
  77.       placement:
  78.         constraints:
  79.          - "node.role==manager"
  80.     networks:
  81.      - traefik-socket
  82.  
  83. networks:
  84.   traefik-public:
  85.     external: true
  86.   traefik-socket:
  87.     driver: overlay
  88.     driver_opts:
  89.       encrypted: 'true'
RAW Paste Data