[Noob question] Traefik + Docker + Nodejs app port 3000

Hello guys , currently i was developing two things

  • react app on port 3001
  • node app on port 3000

Later they will work on the same domain, and i want to work that way while developing.

I decided to initiate myself to traefik for this need ..

version: '3.7'

services:
  traefik:
    image: traefik:v2.2
    command: 
      - --api.insecure=true 
      # Docker
      - --providers.docker 
      - --providers.docker.exposedByDefault=false 
      - --providers.docker.network=internal
      - --entrypoints.web.address=:80v02.api.letsencrypt.org/directory
      # Config
      - --accesslog=true
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  whoami:
    image: emilevauge/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost.test`)"
      - "traefik.enable=true"
  api:
    container_name: api
    build:
      context: .
      target: development
    labels:
      #- "traefik.http.services.api-service.loadbalancer.server.port=3000"
      - "traefik.http.routers.api-router.rule=Host(`api.brainstoo.localhost.test`)"
      - "traefik.enable=true"

Right now i can access my api with the url : api.brainstoo.localhost.test:3000
But i would like to access it directly with api.brainstoo.localhost.test without the port.
Wether i comment or uncomment the line ** #- "traefik.http.services.apiservice.loadbalancer.server.port=3000"** changes nothing.

I don't know what i m doing wrong. Maybe i did not understand well if traefik would resolve this kind of matters.

Thanks in advance.

Hello,

your configuration globally right.

I don't know your app really works but you can follow this configuration:

version: '3.7'

services:
  traefik:
    image: traefik:v2.2
    command: 
      - --api.insecure=true 
      # Docker
      - --providers.docker 
      - --providers.docker.exposedByDefault=false
      - --entrypoints.web.address=:80
    ports:
      - 80:80
      - 8080:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  whoami:
    image: containous/whoami:v1.5.0
    command:
      # It tells whoami to start listening on 3000 instead of 80
      - --port=3000
    labels:
      traefik.enable: true

      traefik.http.routers.whoami.rule: Host(`whoami.docker.localhost`)
      traefik.http.routers.whoami.entrypoints: web
      traefik.http.services.whoami.loadbalancer.server.port: 3000

  api:
    container_name: api
    build:
      context: .
      target: development
    labels:
      traefik.enable: true

      traefik.http.routers.api-router.rule: Host(`api.brainstoo.localhost`)
      traefik.http.routers.api-router.entrypoints: web
      traefik.http.services.api-service.loadbalancer.server.port: 3000

  • http://whoami.docker.localhost -> whoami on 3000
  • http://api.brainstoo.localhost -> api on 3000

No sir, it does not work. Actually , the part with whoami is working

I will try with a simple express server helloworld tomorrow to see if this isnt just my app (nestjs)

Ok , it works with : https://github.com/yaempioy/dockerize-node-hello-world

so it has to do with my app, or confs.

maybe about network since i use specific network on my app .

EDIT: my networks werent the same , i changed them, it works now !!

Hi,
I have a problem with serving Next.js app on Traefik.
Can you please share your Dockerfile? It may help me.

Thank you

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