Routing multiple services using same port on docker provider

I have two services in my docker compose file that use the same 8080 port with these labels:

  adminer:
    image: adminer
    # restart: always
    networks:
      - bridge
    depends_on:
      - traefik
      - db
    labels:
      - traefik.enable=true
      - traefik.http.routers.adminer-router.entrypoints=websecure
      - traefik.http.routers.adminer-router.rule=Host(`db.${PRJ_DOMAIN}`)
      - traefik.http.routers.adminer-router.tls=true
      - traefik.http.routers.adminer-router.tls.certresolver=leresolver
      - traefik.http.routers.adminer-router.service=adminer-service
      - traefik.http.services.adminer-service.loadbalancer.server.url=`http://adminer:8080`

  jenkins:
    image: jenkinsci/blueocean
    networks:
      - bridge
    depends_on:
      - traefik
    environment:
      - DOCKER_HOST=tcp://dind:2376
      - DOCKER_CERT_PATH=/certs/client
      - DOCKER_TLS_VERIFY=1
    ports:
      - "50000:50000"
    volumes:
      - jenkins-data:/var/jenkins_home
      - jenkins-docker-certs:/certs/client:ro
    labels:
      - traefik.enable=true
      - traefik.http.routers.jenkins-router.entrypoints=websecure
      - traefik.http.routers.jenkins-router.rule=Host(`jenkins.${PRJ_DOMAIN}`)
      - traefik.http.routers.jenkins-router.tls=true
      - traefik.http.routers.jenkins-router.tls.certresolver=leresolver
      - traefik.http.routers.jenkins-router.service=jenkins-service
      - traefik.http.services.jenkins-service.loadbalancer.server.url=`http://jenkins:8080`

But traefik gives bad gateway if both services are running and using the same port. If either of the services is disabled, the other one works fine. Containers should be isolated and no port conflict must happen but traefik doesn't seem to handle this properly.

Hello,

The labels traefik.http.services.<service_name>.loadbalancer.server.url are not valid labels:

In a Docker context, and in the majority of the cases, you don't have to define explicitly the port (traefik.http.services.<service_name>.loadbalancer.server.port), Traefik can detect automatically the port.
If Traefik doesn't detect the port, you have to define the port with the following label: traefik.http.services.<service_name>.loadbalancer.server.port.

example:

- traefik.http.services.myservice.loadbalancer.server.port=8080
2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.