This demo will listen to port 80 and port 8080, but you can adjust the values of TRAEFIK_PROXY_PORT
and TRAEFIK_CONSOLE_PORT
to different values.
After checking out the code repository:
- Build the images:
docker-compose build
- Launch containers:
docker-compose up
(it may be useful to view the logs during the sample exercises)
The Traefik console is available by default at http://localhost:8080, and proxied services are behind port 80.
This demo is configured to use hostnames from the traefik.me
domain, which returns 127.0.0.1
for all DNS lookups.
These exercises demonstrate some of Traefik's basic capabilities. Note that the developer makes the decision about how requests are routed to containers by specifying routes in the provider's (i.e. Docker) metadata. Any tool that is able to label a Docker image can be used to provide this information, or it can be embedded in the image by the developer.
- Navigate to the Traefik Console, and view the services. Note the presence of the example services. Traefik discovered them by using the labels configured in
docker-compose.yml
. - Visit http://service.traefik.me/index.html. Traefik knows how to route the request based on the HTTP host header, as specified by the rule
Host(service.traefik.me)
. Note thegroup
in the HTTP response; it's simply a key that all containers started from the same service will share. - Visit http://service.traefik.me/group2/index.html. Note that the group has changed. Traefik routes this request based on the HTTP host header and the path prefix:
Host(service.traefik.me) && PathPrefix(/group2)
- Go ahead and stop one of the services, e.g.
docker-compose stop server
, and see how traefik responds. Note it is gone from services, and its corresponding routers are gone. - Now launch multiple instances of a service by invoking
docker-compose up --scale server=5
, then re-execute your request to http://service.traefik.me/index.html multiple times. You should notice that traefik automatically discovered the new instances (the host name changes), and load balances across them automatically. The size of the scale group is show in services under the "Servers" column.