Home > Enterprise >  Traefik Docker proxy - Cannot change listening port of PHP-Apache
Traefik Docker proxy - Cannot change listening port of PHP-Apache

Time:10-23

I have a simple PHP Laravel docker image, created finally with PHP Apache, listening on port 80 (by default).

I have a Docker Traefik installation that works very well, via HTTPS (443 port).

Now, if I use the following docker-compose.yml for the laravel installation:

version: "3.8"
services:
  resumecv:
    image: sineverba/resumecv-backend:0.1.0-dev
    container_name: resumecv
    networks:
      - proxy
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=proxy"
      - "traefik.http.routers.resumecv-backend.entrypoints=websecure"
      - "traefik.http.routers.resumecv-backend.service=resumecv-backend"
      - "traefik.http.routers.resumecv-backend.rule=Host(`resumecvbackend.example.com`)"
      - "traefik.http.services.resumecv-backend.loadbalancer.server.port=80"

networks:
  proxy:
    external: true

It works (mapped against 80 port).

If I would change the listening port:

version: "3.8"
services:
  resumecv:
    image: sineverba/resumecv-backend:0.1.0-dev
    container_name: resumecv
    networks:
      - proxy
    ports:
      - "9999:80"
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=proxy"
      - "traefik.http.routers.resumecv-backend.entrypoints=websecure"
      - "traefik.http.routers.resumecv-backend.service=resumecv-backend"
      - "traefik.http.routers.resumecv-backend.rule=Host(`resumecvbackend.example.com`)"
      - "traefik.http.services.resumecv-backend.loadbalancer.server.port=9999"

networks:
  proxy:
    external: true

I get a Bad Gateway from Cloudflare (service not reachable).

I know that I could change the Apache port inside the container itself, but I would use the out <-> in mapping with ports definition.

Curl test

From the host, I can curl http://127.0.0.1:9999 with success. I can also browse website using the IP of the host (192.168.1.100:9999).

Label traefik port

I did try to add traefik.port=9999 label without luck

Removing Label balancer

If I remove "traefik.http.services.resumecv-backend.loadbalancer.server.port=9999" label, I get a laconic 404 not found.

CodePudding user response:

Port publishing...

ports:
  - "9999:80"

...doesn't change the port on which your container is listening. It simply establishes a mapping from the host into the container. Your service is still listening on port 80, and that's the port other containers -- including traefik -- will need to use to contact your service.

If you're using a frontend like traefik you don't need the ports entry (because you'll be accessing the service through traefik, rather than directly through a host port).

  • Related