Search code examples
dockerdocker-composedocker-swarmtraefik

Traefik SSL Issue in version 2.1.4


I have a docker swarm cluster. In that cluster, I need to configure Traefik with an SSL entry-point. once I applied my configuration into the traefik it gets some error. Please help me to troubleshoot this issue.

Here is my .toml file,

logLevel = "INFO"

[docker]
  endpoint = "unix:///var/run/docker.sock"
  exposedbydefault = false

[api]
  dashboard =true

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]
      [[entryPoints.https.tls.certificates]]
      certFile = "/root/ssl/mi-synergy.com.crt"
      keyFile = "/root/ssl/mi-synergy.com.key"

Here is my Stack file

version: "3.7"
services:
  traefik:
    image: traefik:2.1.4
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /root/traefik.toml:/etc/traefik/traefik.toml
      - /root/ssl:/root/ssl
    networks:
      - webgateway
      - traefik
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    deploy:
      mode: global
      placement:
        constraints:
          - node.role == manager
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure

networks:
  webgateway:
    driver: overlay
  traefik:
    driver: overlay

The log extract is

[email protected]    | 2020/02/25 14:29:58 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:30:06 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:30:14 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:30:22 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:30:30 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:30:38 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:30:46 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:30:54 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:31:02 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:31:09 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:31:17 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:31:25 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:31:33 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:31:41 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:31:49 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:31:57 command traefik error: field not found, node: redirect
[email protected]    | 2020/02/25 14:32:05 command traefik error: field not found, node: redirect

Solution

  • you can try the following docker stack

    version: "3.7"
    services:
      traefik:
        image: traefik:2.1.4
        command:
          - '--providers.docker=true'
          - '--providers.providersThrottleDuration=2s'
          - '--providers.docker.watch=true'
          - '--providers.docker.swarmMode=true'
          - '--providers.docker.swarmModeRefreshSeconds=15s'
          - '--providers.docker.exposedbydefault=false'
          - '--providers.docker.defaultRule=Host("${REPLACE_WITH_YOUR_DOMAIN}")'
          - '--accessLog.bufferingSize=0'
          - '--api=true'
          - '--api.dashboard=true'
          - '--api.insecure=true'
          - '--ping.entryPoint=web'
          - '--providers.file.filename=/run/traefik.toml'
          - '--entryPoints.web.address=:80'
          - '--entryPoints.websecure.address=:443'
        volumes:
          - '/var/run/docker.sock:/var/run/docker.sock:ro'
          - '/root/traefik.toml:/run/traefik.toml'
          - '/root/ssl:/root/ssl'
        networks:
          - webgateway
          - traefik
        ports:
          - 80:80
          - 443:443
          - 8080:8080
        deploy:
          labels:
            - traefik.enable=true
            - traefik.docker.network=traefik
            - traefik.http.middlewares.https_redirect.redirectscheme.scheme=https
            - traefik.http.middlewares.https_redirect.redirectscheme.permanent=true
            - traefik.http.routers.http_catchall.rule=HostRegexp(`{any:.+}`)
            - traefik.http.routers.http_catchall.entrypoints=web
            - traefik.http.routers.http_catchall.middlewares=https_redirect
          mode: global
          placement:
            constraints:
              - node.role == manager
          update_config:
            parallelism: 1
            delay: 10s
          restart_policy:
            condition: on-failure
    
    networks:
      webgateway:
        driver: overlay
      traefik:
        driver: overlay
    

    traefik.toml

    [[tls.certificates]]
      certFile = "/root/ssl/mi-synergy.com.crt"
      keyFile = "/root/ssl/mi-synergy.com.key"
    
    

    make sure that the ssl certs exist on the host machine under /root/ssl and traefik config file under /root/traefik.toml otherwise, it will not be available to the container. if you are running this in a multi-node swarm it should be in every nodes (not only the manager) since you used global deployment mode