-1

please help! I am trying to start a service SonarQube with proxy Traefik. But all time have error 404. Please help me configure traefik to expose my services on swarm. We are going to deploy more than 10 servicies.

My swarm.yml:

version: "3.7"

services:   traefik:
    image: "traefik:v2.1"
    networks:
      - traefik-public
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./traefik.yml:/traefik.yml:ro

  sonar:
    image: sonarqube:8.9-community
    networks:
      - pg-net
      - traefik-public
    ports:
      - "9000:9000"
    environment:
      - SONAR_JDBC_URL=jdbc:postgresql://sqdb:5432/sonarqube
      - SONAR_JDBC_USERNAME=sonarqube
      - SONAR_JDBC_PASSWORD=N1eC7ALj1P1bOf4!wyhQi
    labels:
      - "traefik.port=9000"
      - "traefik.docker.network=traefik-public"
      - "traefik.enable=true"
      - "traefik.http.routers.sonar.entrypoints=web"
      - "traefik.http.routers.sonar.rule=Host('sonar.example.com')"
    
networks:   traefik-public:
    external: true

Example of traefik.yml:

## STATIC CONFIGURATION
log:
  level: INFO

api:
  insecure: true
  dashboard: true

entryPoints:
  web:
    address: ":80"

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

1 Answers1

0

As per documentation:

While in Swarm Mode, Traefik uses labels found on services, not on individual containers.

Therefore, if you use a compose file with Swarm Mode, labels should be defined in the deploy part of your service.

Please also note additional part:

Docker Swarm does not provide any port detection information to Traefik.

Therefore, you must specify the port to use for communication by using the label traefik.http.services.<service_name>.loadbalancer.server.port

You should move your labels to deploy section and fix the port setting, e.g.:

  sonar:
    image: sonarqube:8.9-community
    networks:
      - pg-net
      - traefik-public
    environment:
      - SONAR_JDBC_URL=jdbc:postgresql://sqdb:5432/sonarqube
      - SONAR_JDBC_USERNAME=sonarqube
      - SONAR_JDBC_PASSWORD=N1eC7ALj1P1bOf4!wyhQi
    deploy:
      labels:
        - "traefik.docker.network=traefik-public"
        - "traefik.enable=true"
        - "traefik.http.routers.sonar.entrypoints=web"
        - "traefik.http.routers.sonar.rule=Host('sonar.example.com')"
        - "traefik.http.services.sonar.loadbalancer.server.port=9000"

I would also not publish port 9000 of the service (hence removed from above example) as this would make your service available to everyone without the Traefik proxy. Traefik will be able to communicate with SonarQube as long as they are on the same network.

raspy
  • 3,995
  • 1
  • 14
  • 18