Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose Traefik "error: port is missing" but network_mode is in host mode

I've wrote a docker-compose file to bring up a traefik container, using network_mode="host". But it keeps raising an error:

level=error msg="service "traefik-traefik" error: port is missing" providerName=docker

It is just docker and docker-compose, in a single node vps, and I am not using swarm. The traefik version is 2.5

Here is my docker-compose.yaml:

version: '3.7'
services:
  traefik:
    network_mode: "host"
    build:
      context: .
      dockerfile: Dockerfile.traefik
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./traefik-public-certificates:/certificates"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dashboard.rule=Host(`msite.mdomain`)"
      - "traefik.http.routers.dashboard.tls=true"
      - "traefik.http.routers.dashboard.tls.certresolver=letsencrypt"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.middlewares=auth"
      - "traefik.http.middlewares.auth.basicauth.users=suser:spass"

volumes:
  traefik-public-certificates:

traefik.toml:

[entryPoints]
  [entryPoints.web]
    address = ":80"
  [entryPoints.web.http]
    [entryPoints.web.http.redirections]
      [entryPoints.web.http.redirections.entryPoint]
        to = "websecure"
        scheme = "https"

  [entryPoints.websecure]
    address = ":443"

[accessLog]

[api]
dashboard = true

[providers]
  [providers.docker]
    exposedByDefault = false

[certificatesResolvers.letsencrypt.acme]
  email = "[email protected]"
  storage = "/certificates/acme.json"
    [certificatesResolvers.letsencrypt.acme.httpChallenge]
      entryPoint = "web"

As far as I know, the network_mode = "host" removes the dependency to declare the port and the network in the docker-compose.yaml. Any help is welcome.

like image 834
SPinheiro Avatar asked Sep 03 '25 16:09

SPinheiro


2 Answers

I don't know how do you build this docker image, but, this errors about missing ports occur often when the docker build instruction EXPOSE is missing on Dockerfile. If not, post the Dockerfile.traefik content

like image 129
Caique Melo Avatar answered Sep 05 '25 05:09

Caique Melo


Copying an answer from Traefik 2.0 "port is missing" for internal dashboard

Okay, just adding a dummy service port to the labels works

      labels:
        - traefik.enable=true
        - traefik.http.services.justAdummyService.loadbalancer.server.port=1337
        - traefik.http.routers.traefikRouter.rule=Host(`127.0.0.11`)
        - traefik.http.routers.traefikRouter.service=api@internal
        - traefik.http.routers.traefikRouter.entrypoints=http
like image 22
Froosh Avatar answered Sep 05 '25 07:09

Froosh