Does docker.swarmMode require traefik.port label on every service?


Very new to Traefik. I have a test setup with traefik and one backend. I have been using docker stack deploy to test this. Everything was worked as expected, until I added --docker.swarmMode. Once I enable this flag, my backend is skipped due to Filtering container without port.

I'm unclear on if this is expected behavior? I would prefer the previous function whereby a container with a single exposed port automatically had that port selected for routing. Any clarification / assistance is appreciated.

PS - I edited the stack file to remove some HTTPS/LE-related startup flags, it may have some typos from this inline editing

version: "3.7"
    image: traefik:1.7
      - "--api"
      - "--docker"
      # If I enable these two flags, I must also declare the port 
      # - "--docker.swarmMode"
      # - ""
      - "--entrypoints=Name:http Address::80"
      - "--defaultentrypoints=http"
      - "--logLevel=DEBUG"
    # Traefik must run on a manager node for swarm mode operation
          - node.role == manager
      - /var/run/docker.sock:/var/run/docker.sock
      - "80:80"
      - "8080:8080"
    image: nginx:alpine
      # This is not needed if you do not pass the docker.swarmMode flag
      # - "traefik.port=80"
      - ""

Hello @hamiltont,

When using swarm mode, there are 3 required labels:

Required labels:

  • traefik.frontend.rule
  • traefik.port - Without this the debug logs will show this service is deliberately filtered out.
  • - Without this a 504 may occur.

This is intended behavior.

Got it, thanks. One followup - one (of the three) official guides for setting up a Swarm Cluster does not even use the --docker.swarmMode flag. (this one)

What does this flag do inside of Traefik? Does it simply change the way Traefik processes docker event updates (IIUC, Docker likes to change their JSON formats between regular and swarm mode). Or is there some really foundational changes that happen inside of Traefik when you run the docker provider in swarm mode?

That is an old user guide from before swarm was integrated into docker engine. It is kept around, as some users have legacy systems, but will not be migrated to the new v2.0 documentation.

The flag tells Traefik to look at services and replicas instead of containers, as the API for networking in swarm mode is quite different than bare docker compose.

The other issue is that in swarm mode, the configuration is added to the deploy section of the service, not the actual container itself, so the flag tells Traefik where to look for its configuration label.

1 Like

Got it. Thanks for the quick answers