Docker Compose example
- Edit a file with the following content:
Networking
The Traefik container has to be attached to the same network as the containers to be exposed. If no networks are specified in the Docker Compose file, Docker creates a default one that allows Traefik to reach the containers defined in the same file. You can as described in the example below. You can use a pre-existing network too.
version: "3.3"
networks:
traefiknet: {}
services:
traefik:
image: "traefik:v2.10"
- traefiknet
whoami:
image: "traefik/whoami"
...
networks:
- traefiknet
- Replace
whoami.localhost
by your own domain within thetraefik.http.routers.whoami.rule
label of thewhoami
service. - Run within the folder where you created the previous file.
Details
As an example, we use whoami (a tiny Go server that prints OS information and HTTP request to output) which was used to define our
simple-service
container.
command:
# Traefik will listen to incoming request on the port 80 (HTTP)
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- We expose the Traefik API to be able to check the configuration if needed:
If you are working on a remote server, you can use the following command to display configuration (require curl
& jq
):
- We allow Traefik to gather configuration from Docker:
Using Traefik for Business Applications?
Traefik Enterprise simplifies the discovery, security, and deployment of APIs and microservices across any environment. See it in action in this short video walkthrough.