skip to Main Content

I would like to have Traefik & traefik/whoami containers up and running. Then access the whoami server via Traefik container.

I am using MacBook with M2 chip, that’s armv8 architecture. So, the image I use for "whoami" server is traefik/whoami which support armv8.

I run them in my local Docker Desktop environment.

Here is my docker-compose.yml:

version: '3'

services:
  traefik:
    # The latest official supported Traefik docker image
    image: traefik:v2.3
    # Enables the Traefik Dashboard and tells Traefik to listen to docker
    # --providers tell Traefik to connect to the Docker provider
    # enable --log.level=INFO so we can see what Traefik is doing in the log files
    command: --api.insecure=true --providers.docker --log.level=INFO
    ports:
      # Exposes port 80 for incomming web requests
      - "80:80"
      # The Web UI port http://0.0.0.0:8080 (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events e.g. container starting
      - /var/run/docker.sock:/var/run/docker.sock

# Add the whoami service
  whoami:
     # A container that exposes an API to show its IP address
     image: traefik/whoami
     # We set a label to tell Traefik to assign a hostname to the new service
     labels:
       - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"

As you can see above, in the whoami service, I have set a Traefik host rule, that whoami.docker.localhost should point to "whoami" server.

I run docker-compose up -d, there is no problem. Both containers are up and running successfully.
enter image description here

Then, I open browser (Chrome) to access the host, no server response:
enter image description here

I also tried to access the Traefik dashboard http://localhost:8080, it is also can not be reached…

What am I missing?

2

Answers


  1. I think you might be missing a few configuration options under "labels" in your whoami service – namely traefik.enable and traefik.http.routers.whoami.entrypoints=web.

    Taken from https://hub.docker.com/r/traefik/whoami:

      whoami:
        image: "traefik/whoami"
        container_name: "simple-service"
        labels:
          - "traefik.enable=true"
          - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
          - "traefik.http.routers.whoami.entrypoints=web"
    
    Login or Signup to reply.
  2. Here’s my solution. I’ve added networks for both the containers along with hostname for whoami. I’m using Windows but I’m sure this is going to work for everyone.

    version: "3.9"
    
    services:
      portal-traefik:
        container_name: portal-traefik
        command:
          - --api.insecure=true
          - --providers.docker=true
          - --providers.docker.exposedbydefault=false
          - --entrypoints.web.address=:80
        image: traefik:latest
        networks:
          api_driven:
        ports:
          - "80:80"
          - "8080:8080"
        restart: unless-stopped
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock:ro
    
      whoami:
        container_name: whoami-traefik
        # A container that exposes an API to show its IP address
        image: traefik/whoami
        # We set a label to tell Traefik to assign a hostname to the new service
        labels:
          - traefik.enable=true
          - traefik.http.routers.whoami.rule=Host(`docker.internal.localhost`)
          - traefik.http.routers.whoami.entrypoints=web
        networks:
          api_driven:
        restart: unless-stopped
        hostname: docker.internal.localhost
    
    networks:
      api_driven:
        name: "api_driven"
    

    Output:

    Hostname: docker.internal.localhost
    IP: 127.0.0.1
    IP: 192.168.240.2
    RemoteAddr: 192.168.240.3:43628
    GET / HTTP/1.1
    Host: docker.internal.localhost
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
    Accept-Encoding: gzip, deflate, br
    Accept-Language: en-US,en;q=0.9,ur;q=0.8,ja;q=0.7,pa;q=0.6
    Cache-Control: max-age=0
    Sec-Ch-Ua: "Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"
    Sec-Ch-Ua-Mobile: ?0
    Sec-Ch-Ua-Platform: "Windows"
    Sec-Fetch-Dest: document
    Sec-Fetch-Mode: navigate
    Sec-Fetch-Site: none
    Sec-Fetch-User: ?1
    Upgrade-Insecure-Requests: 1
    X-Forwarded-For: 192.168.240.1
    X-Forwarded-Host: docker.internal.localhost
    X-Forwarded-Port: 80
    X-Forwarded-Proto: http
    X-Forwarded-Server: 16ca92e14aa2
    X-Real-Ip: 192.168.240.1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search