Faulty configuration cannot reach container

Hello together,

I am still a big beginner with Traefik. I'm currently trying to boot a construct (first without encryption to be able to start it). Unfortunately the service doesn't seem to find the URL of the container.

Briefly a little background:
I'm running Traefik as a Docker container. Further projects / websites I will put on the server as own Docker-Compose, and start them up. These should register with Traefik and thus be accessible.

I have created a shared network "proxy" on the server in advance.

My configuration for Traefik looks like this:

providers:
  docker:
    exposedByDefault: false
    watch: true
    allowEmptyServices: true
    network: proxy
    useBindPortIP: true

log:
  filePath: "/etc/traefik/logs/log-file.log"
  level: "ERROR"

api:
  dashboard: true
  insecure: true

## Static configuration
entryPoints:
  web:
    address: ":80"
  websecure:
    address: ":443"

certificatesResolvers:
  lets-encrypt:
    acme:
      email: kontakt@localhost
      storage: acme.json
      httpChallenge:
          entryPoint: web

My Docker Compose for Traefik:

version: '3'

services:
  reverse-proxy:
    image: traefik
    container_name: "traefik"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik:/etc/traefik
    labels:
      - traefik.enable=true
      - traefik.http.routers.traefik.rule=Host(`traefik.localhost`)
#      - traefik.http.routers.traefik.tls.certresolver=lets-encrypt
      - traefik.http.routers.traefik.service=traefik@docker
      - traefik.http.services.traefik.loadbalancer.server.port=8080
      - traefik.http.services.traefik.loadbalancer.server.url=http://traefik:8080
    networks:
      - proxy
      - default

networks:
  proxy:
    external: true
  default:
    driver: bridge

The config for Docker Compose:

My separate service that is unreachable as Docker Compose:

version: '3'
services:
  mvo-web:
    build:
      context: .
      args:
        PORT: ${WEB_PORT}
    restart: unless-stopped
    container_name: "mvo-web"
    labels:
      - traefik.enable=true
      - traefik.http.routers.mvo-web.rule=Host(`neu.localhost`)
      #      - traefik.http.routers.mvo-web.tls.certresolver=lets-encrypt
      - traefik.http.routers.mvo-web.service=mvo-web@docker
      - traefik.http.services.mvo-web.loadbalancer.server.port=${WEB_PORT}
      - traefik.http.services.mvo-web.loadbalancer.server.url=http://mvo-web:${WEB_PORT}
    ports:
      - ${WEB_PORT}:${WEB_PORT}
    env_file: .env
    environment:
      PORT: ${WEB_PORT}
      NODE_ENV: ${NODE_ENV}
    volumes:
      - ./:/opt/app
    networks:
      - proxy
      - default

  mvo-api:
    build:
      context: container/cms/.
      args:
        PORT: ${API_PORT}
    image: strapi:latest
    restart: unless-stopped
    container_name: "mvo-api"
    labels:
      - traefik.enable=true
      - traefik.http.routers.mvo-api.rule=Host(`api.localhost`)
      #      - traefik.http.routers.mvo-api.tls.certresolver=lets-encrypt
      - traefik.http.routers.mvo-api.service=mvo-api@docker
      - traefik.http.services.mvo-api.loadbalancer.server.port=${API_PORT}
      - traefik.http.services.mvo-api.loadbalancer.server.url=http://mvo-api:${API_PORT}
    ports:
      - ${API_PORT}:${API_PORT}
    env_file: .env
    environment:
      DATABASE_CLIENT: ${DATABASE_CLIENT}
      DATABASE_HOST: ${DATABASE_HOST}
      DATABASE_PORT: ${DATABASE_PORT}
      DATABASE_NAME: ${DATABASE_NAME}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
      JWT_SECRET: ${JWT_SECRET}
      ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET}
      APP_KEYS: ${APP_KEYS}
      NODE_ENV: ${NODE_ENV}
      PORT: ${API_PORT}
    volumes:
      - ./container/cms/config:/opt/app/config
      - ./container/cms/public:/opt/app/public
      - ./container/cms/src:/opt/app/src
      - ./container/cms/extensions:/opt/app/extensions
      - ./container/cms/.env:/opt/app/.env
      - ./container/cms/package.json:/opt/app/package.json
    networks:
      - proxy
      - default

  mvo-db:
    container_name: "mvo-db"
    platform: linux/amd64
    restart: unless-stopped
    env_file: .env
    image: mariadb:latest
    environment:
      MYSQL_USER: ${DATABASE_USERNAME}
      MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD}
      MYSQL_PASSWORD: ${DATABASE_PASSWORD}
      MYSQL_DATABASE: ${DATABASE_NAME}
    volumes:
      - strapi-data:/var/lib/mysql
      - ./container/db:/var/lib/mysql
    ports:
      - ${DATABASE_PORT}:${DATABASE_PORT}
    networks:
      - default

volumes:
  strapi-data:

networks:
  proxy:
    external: true
  default:
    driver: bridge

Screenshot as seen in Traefik.

I've been looking for a solution for days now. Unfortunately, nothing could really help so far and I hope here for a solution.

I recommend to set docker.network (globally on provider.docker or individual on the labels) so Traefik knows which Docker network to use to forward requests, as you have multiple.

loadbalancer.server.url does not exist in Docker configuration discovery with labels, the target service is automatically set.

Simple Traefik example with docker-compose.yml.

Thank you, I have now removed url. But it does not work.

Like you, I also go through a shared network. I have created the network in advance. But my problem is existing.

The problem occurs only for other docker compose which are registered separately. You can see above that they are all in the same network.

I always run into the same problem no matter what approach I take. It searches for servers in Traefik. As soon as I address a custom port, it has the problem....

It finds services like the DB and the whoami and can recognize the servers correctly. Only those with the custom ports e.g. 8084 not.

I urgently need help for this. I've been looking for a solution for weeks now!

version: '3'
services:
  wd-web:
    build:
      context: .
      args:
        PORT: ${WEB_PORT}
    restart: unless-stopped
    container_name: "wd-web"
    labels:
      - traefik.http.routers.wd-web.rule=Host(`w2.waldheim.de`)
      - traefik.http.routers.wd-web.entrypoints=websecure,web
      - traefik.http.routers.wd-web.service=wd-web-waldheimdevhomepage@docker
      - traefik.http.services.wd-web-waldheimdevhomepage.loadbalancer.server.port=${WEB_PORT}
      - traefik.http.services.wd-web-waldheimdevhomepage.loadbalancer.healthcheck.path=/health
      - traefik.http.services.wd-web-waldheimdevhomepage.loadbalancer.healthcheck.interval=10s
      - traefik.http.services.wd-web-waldheimdevhomepage.loadbalancer.healthcheck.timeout=5s
      - traefik.http.services.wd-web-waldheimdevhomepage.loadbalancer.healthcheck.port=${WEB_PORT}
      - traefik.http.services.wd-web-waldheimdevhomepage.loadbalancer.healthcheck.hostname=wd-web
      #      - traefik.http.routers.mvo-web.tls.certresolver=lets-encrypt
    ports:
      - ${WEB_PORT}:${WEB_PORT}
    env_file: .env
    environment:
      PORT: ${WEB_PORT}
      NODE_ENV: ${NODE_ENV}
    volumes:
      - ./:/opt/app
    networks:
      - proxy
      - default


networks:
  proxy:
    external: true
  default:
    driver: bridge

Maybe try removing @docker.

I don't know why I would remove that though, since Docker services are automatically registered that way, but okey. Doesn't change anything...

I never needed @docker.

But it doesn't change my problem... It seems to recognize everything, but does not get to the container. The problem seems to be the external docker-compose for the own service.

Do you use Docker Swarm? Is your target service/container running? Have you tried hardcoding your port?

I work without Swarm simple Docker. Do you think it needs Swarm for that? The Container is Running. You can recreate it yourself by doing a Docker compose with Traefik and one with e.g. Whoami service from Traefik and start them one after the other and insert them with CustomPort for whoami. So 8081:80

Ports are fixed by me.

Hi @mwaldheim,
Thanks for your interest in Traefik!

I would suggest to:

  • Run Traefik in DEBUG mode
  • Start with a simplified and shorter config, once you can reach the container, extend your configuration, step-by-step
  • Make sure Traefik and the container in question share the same network and Traefik is configured to use this network
  • Use tools like docker inspect to check your container settings
  • Check as a first step if you can reach the container:port without Traefik, just from container to container
  • Read Traefik Docker Documentation - Traefik for more info
  • Read Traefik EntryPoints Documentation - Traefik for more info

Hope that helps you! Have a nice day!

I was able to find the problem together with a known... It was because the dockers were unhealthy. In addition, the traefik.enable always had to be performed no matter from which service.

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