Hi. I am trying to get Traefik to recognize containers running swarm mode.
I am able to successfully run Traefik in docker without swarm mode using this traefik.yml file
api:
dashboard: true
entryPoints:
web:
address: ":80"
# http:
# redirections:
# entryPoint:
# to: websecure
websecure:
address: ":443"
http:
middlewares:
- secureHeaders@file
tls:
certResolver: letsencrypt
log:
filePath: "/etc/traefik/traefik.log"
providers:
# swarm:
# endpoint: "unix:///var/run/docker.sock"
docker:
endpoint: "unix:///var/run/docker.sock"
# swarmMode: true
exposedByDefault: false
file:
filename: /configurations/dynamic.yml
certificatesResolvers:
letsencrypt:
acme:
email: xxxxxxxxx@gmail.com
storage: acme.json
keyType: EC384
httpChallenge:
entryPoint: web
and this docker-compose file:
version: "3.8"
services:
traefik:
image: "traefik:2.11.0"
container_name: traefik
restart: unless-stopped
security_opt:
- "no-new-privileges:true"
networks:
- traefik_attachable
ports:
- "80:80"
- "443:443"
volumes:
- "/etc/localtime:/etc/localtime:ro"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik.yml:/traefik.yml:ro"
- "./traefik.log:/etc/traefik/traefik.log"
- "./acme.json:/acme.json"
- "./configurations:/configurations"
deploy:
placement:
constraints:
- node.role == manager
labels:
- traefik.enable=true
- traefik.docker.network=traefik_attachable
- traefik.http.routers.traefik-secure.entrypoints=websecure
- traefik.http.routers.traefik-secure.rule=Host(`traefik-server`)
- traefik.http.routers.traefik-secure.service=api@internal
- traefik.http.routers.traefik-secure.middlewares=user-auth@file
networks:
traefik_attachable:
external: true
where the traefik_attachable network is a previously defined overlay network in my swarm. For standard docker-compose, I de-indent the labels, where as for docker stack deploy they are indented under the deploy header. In non-swarm mode Traefik can detect containers started locally on the docker server via docker-compose but it cannot detect any containers that were started via docker stack deploy.
However, when I uncomment swarmMode: true, the container runs and the browser receives the self-signed certificate but the dashboard:
https://traefik-server/dashboard/
returns a 404.
When swarmMode: true is on, the log file this entry:
time="2024-03-06T23:16:58Z" level=error msg="Skip container : field not found, node: enable: true" providerName=docker
I think that the label enable: true is coming from the docker-compose file. However, indenting the labels under the deploy: header does not solve the problem - neither docker-compose nor docker stack deploy makes the container run properly.
I cannot figure out how to get past this - I've read most of the pages that contain "skip container" or "field not found, enable: true" and it seems like what I'm doing should work.
Any ideas on what is wrong would be most appreciated.