Traefik v2.0 does not work for me with any other port other than 80

I have an example project here, that when run using port 80 works as expected. When I change apache's and traefik's port to 8888. Traefik gives me a 'bad gateway' error and logs:

502 Bad Gateway' caused by: dial tcp 192.168.64.3:80: connect: connection refused"

Can anyone have a look to see if they can replicate this/provide me with a solution? My intention is to run apache on non- privileged ports.

Here are the files:

Dockerfile:

FROM php:7.3-apache-stretch
RUN touch /var/www/html/index.html
RUN sed -ri "s!Listen 80!Listen 8888!" /etc/apache2/ports.conf
RUN sed -ri "s!<VirtualHost *:80>!<VirtualHost *:8888>!" /etc/apache2/sites-available/000-default.conf
CMD ["apache2-foreground"]

docker-compose.yml:

version: '3.7'
services:
  traefik:
    restart: always
    image: traefik:v2.0.0-rc1
    ports:
      - 8888:8888
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: 
      --entrypoints.web.address=:8888
      --providers.docker=true 
      --log.level=DEBUG
  apache:
    build: 
      context: .
    restart: "no"
    labels:
      - traefik.http.routers.router1.entrypoints=web
      - traefik.http.routers.router1.rule=Host(
        `localhost`)
    depends_on: 
      - traefik

the port (8888) is the port exposed by Traefik, it's not related to the port of your apache container.

You have to use traefik.http.services.service1.loadbalancer.server.port as following:

  apache:
    build: 
      context: .
    restart: "no"
    labels:
      - traefik.http.routers.router1.entrypoints=web
      - traefik.http.routers.router1.rule=Host(`localhost`)
      - traefik.http.routers.router1.service=service1
      - traefik.http.services.service1.loadbalancer.server.port=8888 # <---
1 Like

Thank you!!!!!!!!! Amazing it works now. What does it do and how come 80/443 doesn't need it?