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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With