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-Port: 80
      11. X-Forwarded-Proto: http
      12. X-Forwarded-Server: 7f0c797dbc51
      13. X-Real-Ip: 192.168.64.1

    Details

    • We define an entry point, along with the exposure of the matching port within docker-compose, which basically allow us to “open and accept” HTTP traffic:

    • 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"

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