"404 backend not found" error when trying to access domain on Docker Swarm

I am struggling with this for a week now, and I am not sure what I am doing wrong :frowning:

I can confirm that all services are up and running on the Swarm cluster.

Here is my docker-compose file:

version: '3'

volumes:
  traefik_acme:
    driver: local

services:

  worker: &worker
    env_file: .env
    restart: always
    build: ../edvay
    image: ${DOCKER_REGISTRY}/${SETUP_ENV}_worker:1
    command: celery -A tasks.celery worker --loglevel=info

  backend:
    <<: *worker
    command: gunicorn autoapp:app -b :${BACKEND_PORT}
    deploy:
      labels:
        - "traefik.backend.domain=${BACKEND_DOMAIN}"
        - "traefik.docker.lbswarm=true"
        - "traefik.enable=true"
        - "traefik.frontend.rule=Host:${BACKEND_DOMAIN}"
        - "traefik.http.routers.backend.rule=Host(`${BACKEND_DOMAIN}`)"
        - "traefik.http.routers.backend.service=backend"
        - "traefik.http.routers.backend.tls.domains[0].main=${BACKEND_DOMAIN}"
        - "traefik.http.services.backend.loadbalancer.server.port=${$BACKEND_PORT}"

  traefik:
    env_file: .env
    build: traefik
    image: ${DOCKER_REGISTRY}/${SETUP_ENV}_traefik:2
    depends_on:
      - backend
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - traefik_acme:/etc/traefik/acme/ # Defined in traefik/traefik.toml
    ports:
      - 0.0.0.0:80:80
      - 0.0.0.0:443:443
    deploy:
      placement:
        constraints:
          - node.role == manager

Here is traefik.toml

logLevel = "INFO"
defaultEntryPoints = ["https", "http"]

[retry]

# [docker]
# exposedByDefault = false


[Global]
debug = true

[log]
level = "DEBUG"

[accessLog]
# format = "json"

[api]
entryPoint = "traefik"
dashboard = true

[ping]

[providers.docker]
  swarmMode = true
  # endpoint = "unix:///var/run/docker.sock"
  exposedByDefault = false

# Entrypoints, http and https
[entryPoints]
  # http should be redirected to https
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  # https is the default
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

[acme]
email = "dhilipsiva@pm.me"
storage = "/etc/traefik/acme/acme.json"
entryPoint = "https"
acmeLogging = true
onHostRule = true
# caServer = "https://acme-staging-v02.api.letsencrypt.org/directory"
# Default: "https://acme-v02.api.letsencrypt.org/directory"

  [acme.dnsChallenge]
  provider = "route53"

I tried all possible combinations of labels and nothing seemed to work.
I build images and push it to AWS ECR. I deploy with docker deploy -c docker-compose.yml
Can someone please point out what I am dong wrong?
When I try accessing with $BACKEND_DOMAIN, it only throws a 404 backend not found

Did you create a separate router for Traefik? HTTPS returns `404 page not found`

2 Likes

Oh wow, today must be my lucky day. I got hold of the elusive @ChillarAnand .

I put these labels

        - "traefik.http.routers.backend.rule=Host(`${BACKEND_DOMAIN}`)"
        - "traefik.http.routers.backend.service=backend"
        - "traefik.http.routers.backend.tls.domains[0].main=${BACKEND_DOMAIN}"

Entry points are defined in traefik.toml I will also try putting entrypoint labels in the moring and see if it solves anything.

Thanks for the link buddy.