Traefik v2 with docker compose - external services possible?

Hi!
I am running Traefik in a docker container with docker compose. In an earlier thread someone helped and told me that it is not possible to mix a file configuration with a configuration in docker compose. So I decided to configure all attributes - static as well as dynamic - in the docker compose file. The file looks like this (I cut the other container configurations):

version: "3.3"
services:
  traefik:
    image: "traefik:latest"
    container_name: "traefik"
    ports:
      - "x.x.x.x:8080:8080"
      - "80:80"
      - "443:443"
    networks:
      - "proxy"
    environment:
      - HTTPREQ_ENDPOINT=http://x.x.x.x:xxxx
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--global.checkNewVersion=true"
      - "--api"
      - "--log.filePath=/logs/traefik.log"
      - "--log.level=INFO"
      - "--accessLog.filePath=/logs/access.log"
      - "--accessLog.bufferingSize=100"
      - "--entryPoints.api.address=:8080"
      - "--entryPoints.web.address=:80"
      - "--entryPoints.web.http.redirections.entryPoint.to=websecure"
      - "--entryPoints.web.http.redirections.entryPoint.scheme=https"
      - "--entryPoints.websecure.address=:443"
      - "--certificatesResolvers.letsencrypt.acme.email=ssladmin@xxxxxxxxx.com"
      - "--certificatesResolvers.letsencrypt.acme.storage=acme/acme.json"
      - "--certificatesResolvers.letsencrypt.acme.dnsChallenge"
      - "--certificatesResolvers.letsencrypt.acme.dnsChallenge.provider=httpreq"
      - "--certificatesResolvers.letsencrypt.acme.dnsChallenge.delayBeforeCheck=7"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "/home/traefik/acme:/acme"
      - "/home/traefik/logs:/logs"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api.rule=Host(`x.x.x.x`)"
      - "traefik.http.routers.api.entryPoints=api"
      - "traefik.http.routers.api.service=api@internal"
      - "traefik.http.routers.api.middlewares=api-auth"
      - "traefik.http.middlewares.api-auth.basicauth.users=admin:xxxxxxxxxxxxxxx"

      - "traefik.http.services.freiberg-oh.loadBalancer.server.url=http://x.x.x.x:8080/"

      - "traefik.http.routers.freiberg.rule=Host(`freiberg.xxxxxxxxx.de`)"
      - "traefik.http.routers.freiberg.service=freiberg-oh"
      - "traefik.http.routers.freiberg.entryPoints=websecure"
      - "traefik.http.routers.freiberg.tls"
      - "traefik.http.routers.freiberg.tls.domains[0].main=freiberg.xxxxxxxx.de"
      - "traefik.http.routers.freiberg.tls.domains[0].sans=*.freiberg.xxxxxxxxx.de"
      - "traefik.http.routers.freiberg.tls.certresolver=letsencrypt"

    restart: always

Everything (the other containers) is running smoothly so far but the external configuration for "freiberg". What I want to achieve is to point the domain "freiberg.xxxxxxxxx.de" to an external web server. In the docs section of Traefik I just found examples for other docker container configurations. What also confuses me is that in the services documentation the attribute for the forwarding url is "http.services.appv1.loadBalancer.servers.url" but in the Traefik docker compose reference there is no such attribute. Also, if I use the line "traefik.http.services.freiberg-oh.loadBalancer.servers.url=http://x.x.x.x:8080/" in my docker-compose.yml, I get an error message:

level=error msg="field not found, node: servers" providerName=docker container=traefik-traefik-fc2923843fdfd57d4cf6a8f5111832204a033d4d7195c3d91e1a10c827a366d3

If I get rid of the s at "servers", there is at least no error message but the forwarding is not working (Connection refused). Any advise?

Hello,

traefik.http.services.freiberg-oh.loadBalancer.server.url is non a valid label.

Also it's not possible to define the URL of a service with the docker provider.

In your case, you have to use the file provider: File | Traefik | v2.2

1 Like

ok, but I still don't get it: how can I use Traefik with docker containers AND external services at the same time? Do I have to use a configuration file for dynamic (and static?) attributes just for the Traefik container and can still use Traefik labels in other container configurations?
Or do I have to use two Traefik instances, one for containers (docker provider) and one for external services (file provider)?

You have to use one Traefik with the 2 providers (file and Docker)

The providers handle only the dynamic configuration.

1 Like

Ahh, got it! :grinning:
Because of your earlier comment that the static configuration can only be configured exclusively as command line arguments or in a configuration file I was under the (wrong!) impression that this behavior also applies to providers (either docker or file). I think I finally got it working now.

Please, share the right configuration: I'm also stuck with the same problem :frowning:

1 Like

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