traefik.yml 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. version: '3.3'
  2. services:
  3. traefik:
  4. # Use the latest v2.2.x Traefik image available
  5. image: traefik:v2.2
  6. ports:
  7. # Listen on port 80, default for HTTP, necessary to redirect to HTTPS
  8. - 80:80
  9. # Listen on port 443, default for HTTPS
  10. - 443:443
  11. deploy:
  12. placement:
  13. constraints:
  14. # Make the traefik service run only on the node with this label
  15. # as the node with it has the volume for the certificates
  16. - node.labels.traefik-public.traefik-public-certificates == true
  17. labels:
  18. # Enable Traefik for this service, to make it available in the public network
  19. - traefik.enable=true
  20. # Use the traefik-public network (declared below)
  21. - traefik.docker.network=traefik-public
  22. # Use the custom label "traefik.constraint-label=traefik-public"
  23. # This public Traefik will only use services with this label
  24. # That way you can add other internal Traefik instances per stack if needed
  25. - traefik.constraint-label=traefik-public
  26. # admin-auth middleware with HTTP Basic auth
  27. # Using the environment variables USERNAME and HASHED_PASSWORD
  28. - traefik.http.middlewares.admin-auth.basicauth.users=${USERNAME?Variable not set}:${HASHED_PASSWORD?Variable not set}
  29. # https-redirect middleware to redirect HTTP to HTTPS
  30. # It can be re-used by other stacks in other Docker Compose files
  31. - traefik.http.middlewares.https-redirect.redirectscheme.scheme=https
  32. - traefik.http.middlewares.https-redirect.redirectscheme.permanent=true
  33. # traefik-http set up only to use the middleware to redirect to https
  34. # Uses the environment variable DOMAIN
  35. - traefik.http.routers.traefik-public-http.rule=Host(`${DOMAIN?Variable not set}`)
  36. - traefik.http.routers.traefik-public-http.entrypoints=http
  37. - traefik.http.routers.traefik-public-http.middlewares=https-redirect
  38. # traefik-https the actual router using HTTPS
  39. # Uses the environment variable DOMAIN
  40. - traefik.http.routers.traefik-public-https.rule=Host(`${DOMAIN?Variable not set}`)
  41. - traefik.http.routers.traefik-public-https.entrypoints=https
  42. - traefik.http.routers.traefik-public-https.tls=true
  43. # Use the special Traefik service api@internal with the web UI/Dashboard
  44. - traefik.http.routers.traefik-public-https.service=api@internal
  45. # Use the "le" (Let's Encrypt) resolver created below
  46. - traefik.http.routers.traefik-public-https.tls.certresolver=le
  47. # Enable HTTP Basic auth, using the middleware created above
  48. - traefik.http.routers.traefik-public-https.middlewares=admin-auth
  49. # Define the port inside of the Docker service to use
  50. - traefik.http.services.traefik-public.loadbalancer.server.port=8080
  51. volumes:
  52. # Add Docker as a mounted volume, so that Traefik can read the labels of other services
  53. - /var/run/docker.sock:/var/run/docker.sock:ro
  54. # Mount the volume to store the certificates
  55. - traefik-public-certificates:/certificates
  56. command:
  57. # Enable Docker in Traefik, so that it reads labels from Docker services
  58. - --providers.docker
  59. # Add a constraint to only use services with the label "traefik.constraint-label=traefik-public"
  60. - --providers.docker.constraints=Label(`traefik.constraint-label`, `traefik-public`)
  61. # Do not expose all Docker services, only the ones explicitly exposed
  62. - --providers.docker.exposedbydefault=false
  63. # Enable Docker Swarm mode
  64. - --providers.docker.swarmmode
  65. # Create an entrypoint "http" listening on port 80
  66. - --entrypoints.http.address=:80
  67. # Create an entrypoint "https" listening on port 443
  68. - --entrypoints.https.address=:443
  69. # Create the certificate resolver "le" for Let's Encrypt, uses the environment variable EMAIL
  70. - --certificatesresolvers.le.acme.email=${EMAIL?Variable not set}
  71. # Store the Let's Encrypt certificates in the mounted volume
  72. - --certificatesresolvers.le.acme.storage=/certificates/acme.json
  73. # Use the TLS Challenge for Let's Encrypt
  74. - --certificatesresolvers.le.acme.tlschallenge=true
  75. # Enable the access log, with HTTP requests
  76. - --accesslog
  77. # Enable the Traefik log, for configurations and errors
  78. - --log
  79. # Enable the Dashboard and API
  80. - --api
  81. networks:
  82. # Use the public network created to be shared between Traefik and
  83. # any other service that needs to be publicly available with HTTPS
  84. - traefik-public
  85. volumes:
  86. # Create a volume to store the certificates, there is a constraint to make sure
  87. # Traefik is always deployed to the same Docker node with the same volume containing
  88. # the HTTPS certificates
  89. traefik-public-certificates:
  90. networks:
  91. # Use the previously created public network "traefik-public", shared with other
  92. # services that need to be publicly available via this Traefik
  93. traefik-public:
  94. external: true