dockerdocker-composedockerfile

Forcing traefik to listen on a port different to 80, 8080, 443


I have a docker container named nodeserver that exposes port 3060. I created the next docker-compose.yml to run a node js program that exist in the

nuc0c.cn.lan:5000/node_request:0.0.1 

image. This docker-compose.yml file works and I am able to see my site if using:

http://nuc0c.cn.lan

Yet, what I want is to see my website using some port as:

http://nuc0c.cn.lan:5060

How can I modify my docker-compose file to achieve this result?

services:
  traefik:
    container_name: traefik4node
    # The official v3 Traefik docker image
    image: traefik:v3.3
    # Enables the web UI and tells Traefik to listen to docker
    command:
       --api.insecure=true
       --providers.docker
    ports:
      - "80:80"
      - "8080:8080"
      # The Web UI (enabled by --api.insecure=true)

    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - nodeserver

  nodeserver:
      image: nuc0c.cn.lan:5000/node_request:0.0.1
      # container_name: nodeserver
      tty: true
      labels:            
        - "traefik.http.routers.nodeserver.rule=Host(`nuc0c.cn.lan`)"
        - "traefik.enable=true"
        - "traefik.http.services.my-service.loadbalancer.server.port=3060" # to pass request to node app through port 3060 exposed at container

Solution

  • You map the Traefik port to the port you want by changing

    ports:
      - "80:80"
      - "8080:8080"
    

    in your docker-compose.yml file to

    ports:
      - "5060:80"
      - "8080:8080"
    

    Then your site will be reachable at port 5060 instead of port 80.