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?

how is this possible? The webserver is connected to port 8888 and then Traefik is also connected to port 8888:8888 and it has a LoadBalancer service to 8888. In my case this shows an error
entryPoint http: error preparing server: error opening listener: listen tcp :8888: bind: address already in use, which makes sense right? it is used by apache so is not possible? Or what am I missing here?

Docker is used. Traefik uses ports to listen on the ports on the host. All other services just listen to the ports within the container connected to the Docker network.

Maybe it’s easier to understand with an explicit Docker network, see simple Traefik example.

1 Like

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