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.

    1. version: "3.3"
    2. networks:
    3. traefiknet: {}
    4. services:
    5. traefik:
    6. image: "traefik:v2.10"
    7. - traefiknet
    8. whoami:
    9. image: "traefik/whoami"
    10. ...
    11. networks:
    12. - traefiknet
    • Replace whoami.localhost by your own domain within the traefik.http.routers.whoami.rule label of the whoami 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.

    1. command:
    2. # Traefik will listen to incoming request on the port 80 (HTTP)
    3. - "--entrypoints.web.address=:80"
    4. ports:
    5. - "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.