Docker-compose basic example
- Edit a file with the following content:
- Replace
whoami.localhost
by your own domain within thetraefik.http.routers.whoami.rule
label of thewhoami
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:Hostname: d7f919e54651
IP: 127.0.0.1
IP: 192.168.64.2
GET / HTTP/1.1
Host: whoami.localhost
User-Agent: curl/7.52.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 192.168.64.1
X-Forwarded-Proto: http
X-Forwarded-Server: 7f0c797dbc51
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:
command:
# Traefik will listen on port 8080 by default for API request.
- "--api.insecure=true"
ports:
- "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:
traefik:
# Enabling docker provider
# Do not expose containers unless explicitly told so
- "--providers.docker.exposedbydefault=false"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
whoami:
labels:
# Explicitly tell Traefik to expose this container
- "traefik.enable=true"
# The domain the service will respond to
- "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
# 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 .