1
votes

I had (as all of us who used Docker Cloud) to migrate my app to new environment, so i chose Docker Swarm CE. I am using Traefik as reverse proxy, and before migration it workked with segments just as per documentation, but for some reason it can not deal with those anymore in Swarm.

My service expose ports 3000 and 3001 for given path prefixes. Here is the part of docker-compose.yml for problematic service:

my-service:
image: my-service-image
deploy:
  restart_policy:
    condition: on-failure
  labels:
    traefik.port: 80
    traefik.serviceapi.backend: api
    traefik.serviceapi.frontend.entryPoints: "http,https"
    traefik.serviceapi.frontend.rule: "PathPrefixStrip:/service/api"
    traefik.serviceapi.port: 3000
    traefik.servicesocket.backend: socket
    traefik.servicesocket.frontend.entryPoints: "http,https,ws,wss"
    traefik.servicesocket.frontend.rule: "PathPrefixStrip:/service/socket"
    traefik.servicesocket.port: 3001

but for some reason swarm does not recognise these traefik segments, or I am missing something.

Did anyone have same issue?

Thanks!

UPDATE:

traefik:
image: traefik
command: 
  - "--web" 
  - "--docker" 
  - "--docker.swarmMode" 
  - "--docker.watch" 
  - "--docker.domain=my-domain"
  - "--defaultentrypoints=http,https" 
  - "--entrypoints=Name:http Address::80 Redirect.EntryPoint:https"
  - "--entrypoints=Name:https Address::443 TLS"
  - "--acme" 
  - "--acme.storage=/etc/traefik/acme/acme.json" 
  - "--acme.entryPoint=https" 
  - "--acme.domains=my-domain"
  - "--acme.httpChallenge.entryPoint=http" 
  - "--acme.email=email"
  - "--logLevel=DEBUG" 
deploy:
  restart_policy: 
    condition: on-failure
ports: 
  - 80:80
  - 443:443
  - 8080:8080
volumes: 
  - ./var/run/docker.sock:/var/run/docker.sock
  - ./traefik/acme/acme.json:/etc/traefik/acme/acme.json

I have more than 10 services working properly, only issue is that I cannot reach my-service endpoints, seems that swarm do not recognize traefik segments.

1
Please include the rest of your compose file, paying attention to indentation, include the compose file or command used to start traefik, the traefik logs, and errors you are setting trying to connect to your application. - BMitch

1 Answers

1
votes

I found solution, so it might be helpful to someone: for Docker Swarm you must set traefik.port, EXCEPT you are using segments - in this case you remove traefik.port and just set up ports of your service. In my case i just had to remove traefik.port: 80, and also both .backend's, traefik will create it's own.