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.