Docker-compose basic example

    • Edit a file with the following content:
    • Replace whoami.localhost by your own domain within the traefik.http.routers.whoami.rule label of the whoami service.
    • Run docker-compose up -d within the folder where you created the previous file.
    • Wait a bit and visit http://your_own_domain to confirm everything went fine. You should see the output of the whoami service. Something similar to:

      1. Hostname: d7f919e54651
      2. IP: 127.0.0.1
      3. IP: 192.168.64.2
      4. GET / HTTP/1.1
      5. Host: whoami.localhost
      6. User-Agent: curl/7.52.1
      7. Accept: */*
      8. Accept-Encoding: gzip
      9. X-Forwarded-For: 192.168.64.1
      10. X-Forwarded-Proto: http
      11. X-Forwarded-Server: 7f0c797dbc51
      12. X-Real-Ip: 192.168.64.1

    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.

    • We expose the Traefik API to be able to check the configuration if needed:
    1. command:
    2. # Traefik will listen on port 8080 by default for API request.
    3. - "--api.insecure=true"
    4. ports:
    5. - "8080:8080"

    Note

    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:
    1. traefik:
    2. # Enabling docker provider
    3. # Do not expose containers unless explicitly told so
    4. - "--providers.docker.exposedbydefault=false"
    5. volumes:
    6. - "/var/run/docker.sock:/var/run/docker.sock:ro"
    7. whoami:
    8. labels:
    9. # Explicitly tell Traefik to expose this container
    10. - "traefik.enable=true"
    11. # The domain the service will respond to
    12. - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
    13. # Allow request only from the predefined entry point named "web"

    If you are using Traefik for commercial applications, consider the . You can use it as your:

    Traefik Enterprise enables centralized access management, distributed Let’s Encrypt, and other advanced capabilities. Learn more in .