No services discovered in swarm

I can’t for the life of me figure out how to get services discovered in docker swarm. I have tried enabling everything by default, setting it all up under one stack, adding labels,etc. Is there some magic I am missing?

I am able to get traefik running under my manager just fine. But again. No services are discovered.

I have followed every doc/guide I can find.

Hi, you can show your traefik and one service configuration file?

Here is my compose file for the stack I am working on.

version: '3.3'


services:
  traefik:
    image: traefik:latest
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedByDefault=false"
      - "--entryPoints.websecure.address=:443"
      - "--entryPoints.web.address=:80"
      - "--log.level=debug"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports:
      - "8081:8080"
      - "81:80"
    deploy:
      placement:
        constraints:
          - node.role == manager
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure
  nats-cluster-node-1:
    image: nats:latest
    command: -cluster nats://0.0.0.0:6222 -m 5222 -DV
    deploy:
      replicas: 1
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.nats-cluster-node-1.rule=PathPrefix(`/natsmon/`)"
        - "traefik.http.routers.nats-cluster-node-1.entrypoints=websecure"
    ports:
      - "5222:5222"

Docker version

Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:25:41 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:24:18 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Hello @dev-mull,

If you are wanting to use swarm mode service discovery, you have to enable swarm mode in the docker provider:

https://docs.traefik.io/v2.1/providers/docker/#configuration-examples

Setting:

--providers.docker.endpoint=tcp://127.0.0.1:2375
--providers.docker.swarmMode=true

Should accomplish what you want.

A rebuilt the stack with those options and its still not detecting the services...

I am getting this from the logs of the container


time="2020-02-04T18:27:38Z" level=debug msg="FIXME: Got an status-code for which error does not match any expected type!!!: -1" status_code=-1 module=api
time="2020-02-04T18:27:38Z" 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
time="2020-02-04T18:27:38Z" 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 1.080381816s" providerName=docker

I telneted to 127.0.0.1 2375 on the same host and got a http server..


/usr/bin/dockerd -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock --containerd=/run/containerd/containerd.sock

tcp 0 0 localhost.localdom:2375 0.0.0.0:* LISTEN 40846/dockerd

even if i switch it back to use the socket and map it via volumes i still get the same error (other than now the url is to the socket)

Hi, also need a network to traefik and services.

You can look than my file is a bash not a yaml

To traefik:

labels:

--constraint "node.role==manager" \
--label "traefik.enable=true" \
--label "traefik.docker.network=${NETWORK_TRAEFIK}" \
--label "traefik.http.services.traefik.loadbalancer.server.port=8080" \
--label "traefik.http.routers.api.rule=Host(\`${DOMAIN}\`)" \

...
Commands

--providers.docker.endpoint=unix:///var/run/docker.sock \
--providers.docker.swarmMode=true \
--api.dashboard=true \
--providers.docker.exposedbydefault=false \
--providers.docker.network=proxy \
--entrypoints.web.address=:80 \
--accesslog=true \
--log.level=DEBUG

You need add the same overlay network to service:

...
docker service create \
--network  ${NETWORK_TRAEFIK} \
--label "traefik.enable=true" \  
--label "traefik.http.services.${SERVICE_NAME}.loadbalancer.server.port=80" \
--label "traefik.http.routers.${SERVICE_NAME}.rule=Host(\`${DOMAIN}\`) \
...

For example.

1 Like