2
votes

Traefik simply ignores "labels" configuration.

Following Traefik's main documentation page, we can simply do:

#docker-compose.yml

version: '3'

services:

  traefik:
    image: traefik # The official Traefik docker image
    command: --api --docker # Enables the web UI and tells Træfik to listen to docker
    ports:
      - "80:80"     # The HTTP port
      - "8080:8080" # The Web UI (enabled by --api)
    volumes:
      - ./docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events

  whoami:
      image: emilevauge/whoami # A container that exposes an API to show its IP address
      labels:
        - "traefik.frontend.rule=Host:whoami.docker.localhost"

Then, running docker-compose should be enough (without traefik.toml file):

docker-compose up -d

Results in the expected:

Starting test_traefik_1 ... done
Starting test_whoami_1  ... done

But unfortunately, Traefik's dashboard displays nothing:

No providers found

What have I tried to do:

  • To use also another labels notation:
labels:
  traefik.backend: "whoami"
  traefik.frontend.rule: "Host:whoami.docker.localhost"
  • To follow this guide.
  • To remove "version: '3'", and also changing it to "version: '3.3'".
  • To run $env:DOCKER_HOST="npipe:////./pipe/docker_engine" or $env:DOCKER_HOST="tcp://localhost:2375" on Powershell.
  • To set npipe instead of unix socket:
volumes:
  - type: npipe
    source: ./pipe
    target: /pipe/docker_engine

Nothing works.

Right now, the only way I can see something in the dashboard, is by adding this line to Traefik volumes: "- ./traefik.toml:/traefik.toml", while creating "traefik.toml" file with [file] configurations. I don't want to have this file. I want to have the control inside the "lables" inside docker-compose.yml.

It'll also be nice to know when should I use the traefik.toml file, as opposed to setting lables inside docker-compose.yml. I did not see any information on that.

Edit: docker logs of traefik shows UNIX socket is in use:

time="2018-07-23T10:55:38Z" level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"

time="2018-07-23T10:55:38Z" level=error msg="Provider connection error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, retrying in 13.276739006s"

Docker-compose should use npipe protocol on Windows by default, but it doesn't. Trying to set the Windows' pipe explicitly, to take place instead of the UNIX socket (using npipe of the long syntax):

#docker-compose.yml

version: '3.2'

services:

  traefik:
    image: traefik
    command: --api --docker
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - type: npipe                # here we are
        source: ./pipe
        target: /pipe/docker_engine

But still the logs shows:

time="2018-07-23T10:57:18Z" level=error msg="Provider connection error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, retrying in 4.166259863s"

time="2018-07-23T10:57:23Z" level=error msg="Failed to retrieve information of the docker client and server host: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"

2
Can you post the docker logs of traefik ?Olivier Cazade
@OlivierCazade Yes, I've added the logs. Thanks!TechWisdom
I think this is related to how the docker.sock is mounted. Just a guess but if you run whoami using docker run (without docker-compse), you will have the same error. I don't know how docker on windows work, so, I can not help more.Olivier Cazade
I would expect docker to use named pipes (npipe) instead of docker.sock (unix sockets) on Windows 10 (as docs says). Seems like a bug. Thanks @OlivierCazadeTechWisdom

2 Answers

7
votes

It's possible to use:

volumes:
   - /var/run/docker.sock:/var/run/docker.sock

Only with this workaround in Powershell:

$Env:COMPOSE_CONVERT_WINDOWS_PATHS=1

The reason is this opened bug: https://github.com/docker/for-win/issues/1829 which makes it impossible to mount docker.sock, because it is "not a valid Windows path" (error).

1
votes

The docker.sock file is located at /var/run/docker.sock on a linux environment, not the current directory. Therefore the volume mount is incorrect in your example for a linux environment. That compose file would look like:

version: '3'

services:

  traefik:
    image: traefik # The official Traefik docker image
    command: --api --docker
    ports:
      - "80:80"     # The HTTP port
      - "8080:8080" # The Web UI (enabled by --api)
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  whoami:
      image: emilevauge/whoami 
      labels:
        - "traefik.frontend.rule=Host:whoami.docker.localhost"

Since you are running the command on windows, the docker api is accessed via an npipe or tcp connection. The solution to this appears to be (this may depend on your version of docker for windows):

version: '3'

services:

  traefik:
    image: traefik # The official Traefik docker image
    command: --api --docker --docker.endpoint=npipe:////./pipe/docker_engine
    ports:
      - "80:80"     # The HTTP port
      - "8080:8080" # The Web UI (enabled by --api)
    volumes:
      - //./pipe/docker_engine://./pipe/docker_engine

  whoami:
      image: emilevauge/whoami 
      labels:
        - "traefik.frontend.rule=Host:whoami.docker.localhost"