# Traefik not detecting services in Docker swarm

**URL:** <https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892>\
**Category:** Traefik v2\
**Tags:** docker-swarm, docker\
**Created:** [September 27, 2021, 5:52pm UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892 "2021-09-27T17:52:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![alvarolloret](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/alvarolloret/32/4298_2.png) [@alvarolloret](https://community.traefik.io/u/alvarolloret)\
**Post date:** [September 27, 2021, 5:52pm UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/1 "2021-09-27T17:52:18Z")

</div>

I've managed to deploy a traefik with swarm, see [this post](https://community.traefik.io/t/traefik-in-docker-swarm/11878) in the forum.

However, I'm facing an issue: The services deployed in swarm are not correctly being seen by traefik.

This is the services I'm deploying:

```auto
version: "3.5"

networks:
  web:
    external: 
      name: web
  internal:
    name: internal
    driver: overlay

services:
  mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: mypass
    networks:
      - internal
    labels:
      - traefik.enable=false

  adminer:
    image: adminer:4.6.3-standalone
    deploy:
      labels:
        - traefik.http.routers.adminer.rule=Host(`dbadmin.mywebsite.com`)
        - traefik.http.routers.adminer.tls=true
        - traefik.http.routers.adminer.tls.certresolver=lets-encrypt
        - traefik.http.services.adminer.loadbalancer.server.port = 8080
    networks:
      - internal
      - web
    depends_on:
      - mysql

```

I'm confident that both services have been correctly deployed, see services:

```auto
root@d2e-server-1:~# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
hm71k8yp791d d2e_adminer replicated 1/1 adminer:4.6.3-standalone   
1fwzg0ud332y d2e_mysql replicated 1/1 mysql:5.7                  
tl1vin36sl74 d2e_traefik replicated 1/1 traefik:v2.2 *:80->80/tcp, *:443->443/tcp

```

however, traefik does not detect them. The  
This is the output of the dashboard in swarm:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/5/5785d2e4e1e7a6880206103d16c5422b632f0f3f.png)

When it was deployed with compose (only containers, no services) I had the following dashboard:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/d/d317c7050bdae20569a570fa277f1defd8e8e4cd.png)

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [September 27, 2021, 5:59pm UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/2 "2021-09-27T17:59:07Z")

</div>

> [@alvarolloret](#):
>
> ` - traefik.port=8080`

Invalid label.

Are you sure that traefik is running in swarm mode. The Host rule look suspect of non-swarm mode.

---

<div class="post-metadata">

**Author:** ![alvarolloret](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/alvarolloret/32/4298_2.png) [@alvarolloret](https://community.traefik.io/u/alvarolloret)\
**Post date:** [September 27, 2021, 6:04pm UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/3 "2021-09-27T18:04:31Z")

</div>

Thanks! Just removed it 🙂 still not detecting the host though.

What do you mean the host rule?  
`traefik.http.routers.adminer.rule=Host(`dbadmin.mysite.com`)` is not supposed to work with swarm mode?

Thanks @cakiwi

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [September 27, 2021, 9:28pm UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/4 "2021-09-27T21:28:33Z")

</div>

I'm referring to the Host rule in the dashboard screen shot, it looks like the default rule created by traefik.

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [September 27, 2021, 10:45pm UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/5 "2021-09-27T22:45:42Z")

</div>

Confirmed my suspicion.

Try enabling log.level=debug

Then you should see a line like this on startup:

> IdleConnsPerHost":200},"entryPoints":{"dashboard":{"address":":8080","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http  
> time="2021-09-27T22:10:14Z" level=debug msg="Static configuration loaded {"global":{"checkNewVersion":true},"serversTransport":{"maxIdleConnsPerHost":200},"entryPoints":{"dashboard":{"address":":8080","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{},"udp":{"timeout":"3s"}},"web":{"address":":80","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{"redirections":{"entryPoint":{"to":"websecure","scheme":"https","permanent":true,"priority":2147483646}}},"udp":{"timeout":"3s"}},"websecure":{"address":":443","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{"tls":{}},"udp":{"timeout":"3s"}}},"providers":{"providersThrottleDuration":"2s","docker":{"watch":true,"endpoint":"unix:///var/run/docker.sock","defaultRule":"Host(`{{ normalize .Name }}`)","exposedByDefault":true,"swarmModeRefreshSeconds":"15s"}},"api":{"dashboard":true},"log":{"level":"debug","format":"common"},"pilot":{"dashboard":true}}"

This one is missing swarmMode, I think yours is too.

---

<div class="post-metadata">

**Author:** ![alvarolloret](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/alvarolloret/32/4298_2.png) [@alvarolloret](https://community.traefik.io/u/alvarolloret)\
**Post date:** [September 29, 2021, 8:24am UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/6 "2021-09-29T08:24:53Z")

</div>

Thank you for your research @cakiwi!

If I understand well I should add a flag in my compose for my services such as:  
- traefik.docker.swarmMode=true

however, this does not seem to work either... ☹

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [September 29, 2021, 11:40am UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/7 "2021-09-29T11:40:56Z")

</div>

The setting is static configuration for traefik set on the cli, env or static configuration file. As it is set in your toml it should be running with swamMode. As you are mounting files you may need to remove the traefik service and redploy.

A better approach is to use docker config and docker secrets. Or in the case of static setting use the command line flags in your docker-compose.yaml / stack.yaml

Was your setup missing swarmMode on startup in the logs ?

---

<div class="post-metadata">

**Author:** ![alvarolloret](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/alvarolloret/32/4298_2.png) [@alvarolloret](https://community.traefik.io/u/alvarolloret)\
**Post date:** [October 1, 2021, 7:45am UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/8 "2021-10-01T07:45:32Z")

</div>

Thanks for the tips, I'll try everything out and let you know @cakiwi ! Your help is greatly appreciated 🙂

---

<div class="post-metadata">

**Author:** ![alvarolloret](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/alvarolloret/32/4298_2.png) [@alvarolloret](https://community.traefik.io/u/alvarolloret)\
**Post date:** [October 1, 2021, 9:23am UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/9 "2021-10-01T09:23:20Z")

</div>

you were right, I checked the logs and the swarm traefik service was not started with `swarkMode`. After redeployement, it actually now started as swarm:

```auto
{
    "global": { "checkNewVersion": true },
    "serversTransport": { "maxIdleConnsPerHost": 200 },
    "entryPoints": {
        "web": {
            "address": ":80",
            "transport": {
                "lifeCycle": { "graceTimeOut": 10000000000 },
                "respondingTimeouts": { "idleTimeout": 180000000000 }
            },
            "forwardedHeaders": {},
            "http": {
                "redirections": {
                    "entryPoint": { "to": "websecure", "scheme": "https", "permanent": true, "priority": 2147483647 }
                }
            }
        },
        "websecure": {
            "address": ":443",
            "transport": {
                "lifeCycle": { "graceTimeOut": 10000000000 },
                "respondingTimeouts": { "idleTimeout": 180000000000 }
            },
            "forwardedHeaders": {},
            "http": {}
        }
    },
    "providers": {
        "providersThrottleDuration": 2000000000,
        "docker": {
            "watch": true,
            "endpoint": "unix:///var/run/docker.sock",
            "defaultRule": "Host(`{{ normalize .Name }}`)",
            "exposedByDefault": true,
            "swarmMode": true,
            "network": "web",
            "swarmModeRefreshSeconds": 15000000000
        },
        "file": { "watch": true, "filename": "traefik_dynamic.toml" }
    },
    "api": { "dashboard": true },
    "log": { "level": "DEBUG", "format": "common" },
    "certificatesResolvers": {
        "lets-encrypt": {
            "acme": {
                "email": "alvaro.@gmail.com",
                "caServer": "https://acme-v02.api.letsencrypt.org/directory",
                "storage": "acme.json",
                "keyType": "RSA4096",
                "tlsChallenge": {}
            }
        }
    }
}

```

However, my traekif service is still giving me the error:

`d2e_traefik.a@d2e-server-1 | time="2021-10-01" level=error msg="field not found, node: port " container=d2e-traefik-as providerName=docker`

I've checked [this](https://github.com/traefik/traefik/issues/5732) issue, but since I have the following line in my `deploy: labels:` :  
` - traefik.http.services.traefik.loadbalancer.server.port = 80`  
It should be right. Maybe I'm missing something?

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [October 1, 2021, 12:29pm UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/10 "2021-10-01T12:29:18Z")

</div>

Double check the labels on your traefik service.

```auto
docker service inspect yourtraefikservice | jq .[].Spec.Labels

```

---

<div class="post-metadata">

**Author:** ![alvarolloret](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/alvarolloret/32/4298_2.png) [@alvarolloret](https://community.traefik.io/u/alvarolloret)\
**Post date:** [October 2, 2021, 7:58am UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/11 "2021-10-02T07:58:57Z")

</div>

> [@cakiwi](#):
>
> `docker service inspect yourtraefikservice | jq .[].Spec.Labels`

OMG !! The output pointed me at the right direction!!! 🙂 The output was the following:

```auto
{
  "com.docker.stack.image": "traefik:v2.2",
  "com.docker.stack.namespace": "d2e",
  "traefik.http.services.traefik.loadbalancer.server.port ": "80"
}

```

Note the space in `port `. I changed the label from:  
`- traefik.http.services.traefik.loadbalancer.server.port = 80`  
to  
`- "traefik.http.services.traefik.loadbalancer.server.port=80"`

and no more errors!

Thank you so much for your help @cakiwi !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [October 5, 2021, 7:59am UTC](https://community.traefik.io/t/traefik-not-detecting-services-in-docker-swarm/11892/12 "2021-10-05T07:59:20Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
