3

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 = "msite@mdmain.com"
  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.

SPinheiro
  • 31
  • 1
  • 3
  • I don't believe traefik is designed to run in host mode, it expects to run on the same docker network as other containers, and if all those containers are in host mode, there's no need for a reverse proxy to access their listening ports. – BMitch Aug 02 '21 at 20:00
  • @BMitch thank you for your answer. I've created a network for the traefik reverse proxy, so all services can be listened by the traefik. But almost all the times the traefik service won't get the new services, and I have to restart the traefik service over and over again until it get the new service is runnig. That is why I've tried to run traefik in "host" mode – SPinheiro Aug 02 '21 at 20:19
  • @BMitch I was using ports: 80:80 and 443:443 and declaring the common network to all services. The only host/service that runs without a problem is the traefik dashboard, I guess that it works just because it is in the same docker-compose file. – SPinheiro Aug 02 '21 at 20:24
  • 1
    Sounds like an X-Y problem. If you want help debugging why services aren't working with traefik, that's a different question and we'd need to see that configuration. – BMitch Aug 02 '21 at 22:13

2 Answers2

1

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

Caique Melo
  • 36
  • 1
  • 6
  • True... but I'm getting it for a container within the same stack that isn't even _supposed_ to expose any ports. Any idea how to just get traefik to ignore it? It doesn't have any docker labels, either. Nevermind: Froosh's answer works – Auspex Aug 28 '23 at 19:55
1

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
Froosh
  • 1,025
  • 1
  • 10
  • 13