2

I'm trying to setup a basic system where a traefik container serves as the reverse proxy for a backend nodejs server. Traefik rests in its own container and nodejs has a container as well. The goal here is to allow for updating the nodejs service without any downtime by using docker in swarm mode. Here's the following config I have for my compose and traefik.yml files but I can't seem to get access the traefik dashboard on localhost:8080 or the nodejs server.

The nodejs server is running on the port 9200. Took a look at the existing stack overflow answers and they pretty much have the same config as the one below. Am I missing something here?

compose.yml

version: "3.7"
services:
  api:
    image: example/hobby:v1
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 5
        window: 120s
      rollback_config:
        parallelism: 1
        delay: 20s
        order: stop-first
      update_config:
        parallelism: 1
        delay: 15s
        failure_action: rollback
        order: stop-first
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.api.rule=Host(`localhost`)"
        - "traefik.http.routers.api.entrypoints=insecure"
        # - "traefik.http.routers.api.service=api"
        - "traefik.http.services.api.loadbalancer.server.port=9200"
      placement:
        constraints:
          - node.role == worker
    env_file:
      - ./.env
    networks:
      - verse

  reverse-proxy:
    image: traefik:v2.3
    deploy:
      mode: global
      labels:
        # - "traefik.http.routers.reverse-proxy.middlewares=auth"
        - "traefik.enable=true"
        - "traefik.http.routers.api.entrypoints=insecure"
        - "traefik.http.routers.api.rule=Host(`localhost`)"
      placement:
        constraints: [node.role==manager]
    # ports:
    #   - target: 80
    #     published: 80
    #     mode: host
    #   - target: 8080
    #     published: 8080
    #     mode: host
    networks:
      - verse
    ports:
      - "80:80"
      - "8080:8080" # traefik dashboard
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      # - "/var/run/docker.sock:/var/run/docker.sock"
      - ./traefik.yml:/etc/traefik/traefik.yml

networks:
  verse:
    # driver: overlay
    external: false

traefik.yml

entryPoints:
  insecure:
    address: ":80"
  traefik:
    address: ":8080"

log:
  level: DEBUG
  # filePath: /path/to/log-file.log
  format: json

api:
  # insecure: true
  dashboard: true
  debug: true

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
    swarmMode: true
    watch: true
    network: verse

middlewares:
  auth:
    basicAuth:
      users:
        - "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"

Jude Fernandes
  • 7,437
  • 11
  • 53
  • 90

0 Answers0