Quick Start
Create a file where you will define a reverse-proxy
service that uses the official Traefik image:
That’s it. Now you can launch Traefik!
Start your reverse-proxy
with the following command:
docker-compose up -d reverse-proxy
You can open a browser and go to http://localhost:8080/api/rawdata to see Traefik’s API rawdata (we’ll go back there once we have launched a service in step 2).
Edit your docker-compose.yml
file and add the following at the end of your file.
# ...
image: traefik/whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
The above defines whoami
: a simple web service that outputs information about the machine it is deployed on (its IP address, host, and so on).
Start the whoami
service with the following command:
Go back to your browser () and see that Traefik has automatically detected the new container and updated its own configuration.
When Traefik detects new services, it creates the corresponding routes so you can call them … let’s see! (Here, we’re using curl)
curl -H Host:whoami.docker.localhost http://127.0.0.1
IP: 172.27.0.3
#...
Run more instances of your whoami
service with the following command:
Go back to your browser (http://localhost:8080/api/rawdata) and see that Traefik has automatically detected the new instance of the container.
Finally, see that Traefik load-balances between the two instances of your service by running the following command twice:
curl -H Host:whoami.docker.localhost http://127.0.0.1
The output will show alternatively one of the followings:
Hostname: a656c8ddca6c
IP: 172.27.0.3
Where to Go Next?