Problems with Docker Swarm and Traefik 2.x

Hello,
I have the following problems maybe someone can help me? Thanks in advance
I try to start a reverse proxy service with the following compose file

version: '3.3'

services:
    reverse-proxy:
     image: traefik:latest
     command:
       - "--api.insecure=true"
       - "--providers.docker=true"
       - "--providers.docker.endpoint=tcp://127.0.0.1:2377"
       - "--providers.docker.swarmMode=true"
     ports:
       - 80:80
       - 8080:8080
     volumes:
       - /var/run/docker.sock:/var/run/docker.sock
     deploy:
        mode: global
        placement:
          constraints:
            - node.role == manager

networks:
   default:
    external:
      name:  imixs-proxy-net

unfortunately the log file reports the following

  • level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at tcp://127.0.0.1:2377. Is the docker daemon running?" providerName=docker,
  • level=error msg="Provider connection error Cannot connect to the Docker daemon at tcp://127.0.0.1:2377. is the docker daemon running?, retrying in 8.304770066s" providerName=docker,

or when I change to " - "--providers.docker.endpoint=tcp://127.0.0.1:2375""

  • level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at tcp://127.0.0.1:2375. Is the docker daemon running?" providerName=docker,
  • level=error msg="Provider connection error Cannot connect to the Docker daemon at tcp://127.0.0.1:2375. is the docker daemon running?, retrying in 8.304770066s" providerName=docker,

I'm not sure which port to use? 2377? My two nodes were included with the following command

  • docker swarm join --token SWMTKN-1-681fxfby12y7a62n6vj890CCCCCC 51.75.YX.ABC:2377

the documentation is different (see atachement) but I gues it should be 2377
Cluster is up and running so i think the nodes can communicate with the master over 2377

from https://docs.traefik.io/providers/docker/

The two services are started with the following commands

  • sudo docker stack deploy -c ./management/traefik/docker-compose.yml reverse-proxy
  • sudo docker stack deploy -c ./apps/whoami/docker-compose.yml whoami

Here is the compose file of the whoami service, which I will use to test if it works

version: '3.3'

services:
  whoami:
    # A container that exposes an API to show its IP address
    image: containous/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Host(`whoami.bpmspace.net`)"
      - "traefik.http.services.whoami.loadbalancer.server.port=8080"

networks:
   default:
    external:
      name:  imixs-proxy-net

But first I have the upper problem, by the way, no matter with which port I try ...

Thanks rob

PS Portainer also runs on the Master.

If you do know know what port to use I suggest removing "--providers.docker.endpoint=tcp://127.0.0.1:2377" line altogether. It's for those who knows what port they want traefik to connect to docker.

Happy new Year

Thanks - i finally got it to run with

version: '3.3'

networks:
 imixs-proxy-net:
   external: true
      
services:
    reverse-proxy:
     image: traefik:latest
     command:
      --providers.docker
      --providers.docker.exposedbydefault=false
      --providers.docker.swarmmode=true
      --entryPoints.http.address=":80"
      --accesslog
      --log.level=DEBUG
      --api=true
      --api.dashboard=true
     ports:
       - 80:80
       - 8080:8080
     volumes:
       - /var/run/docker.sock:/var/run/docker.sock
     deploy:
        mode: global
        placement:
          constraints:
            - node.role == manager
        labels:
          - traefik.enable=true
          - traefik.http.services.justAdummyService.loadbalancer.server.port=1337
          - traefik.http.routers.traefikRouter.rule=Host(`traefik.bpmspace.net`)
          - traefik.http.routers.traefikRouter.service=api@internal
          - traefik.http.routers.traefikRouter.entrypoints=http
     networks:
       - imixs-proxy-net

and whois

version: '3.3'

networks:
 imixs-proxy-net:
   external: true
   
services:
  whoami:
    image: containous/whoami
    deploy:
      labels:
        - traefik.enable=true
        - traefik.http.routers.whoami.rule=Host(`whoami.bpmspace.net`)
        - traefik.http.services.whoami-service.loadbalancer.server.port=80
    networks:
      - imixs-proxy-net

Thanks and goodby

1 Like

Nice work. Two issues

I think mode: global under deploy for traefik will cause issues for you if you ever have more than one manager, since then you'll have to load balance the traefik services at a higher level...I think.

Also, for me, this setup (which I had to resort to, since the Traefik docs assume you're deploying traefik with the docker provider on the bare metal host that has the docker daemon running on it, hence the unqualified reference to 127.0.0.1 as the endpoint)...this setup does not work if your reverse proxied services are scaled up, e.g. replicas: 2 in a deploy section for your whoami service.

I haven't found an issue yet, but I think we need to use the endpoint that traefik recommends for swarm mode, but have it accessible from inside the traefik container, via use of host.docker.internal: nginx - From inside of a Docker container, how do I connect to the localhost of the machine? - Stack Overflow