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.
Then, I open browser (Chrome) to access the host, no server response:
I also tried to access the Traefik dashboard http://localhost:8080, it is also can not be reached…
What am I missing?
2
Answers
I think you might be missing a few configuration options under "labels" in your whoami service – namely
traefik.enable
andtraefik.http.routers.whoami.entrypoints=web
.Taken from https://hub.docker.com/r/traefik/whoami:
Here’s my solution. I’ve added
networks
for both the containers along withhostname
forwhoami
. I’m using Windows but I’m sure this is going to work for everyone.Output: