Multiple domains for the same container with Traefik
This example shows how you can configure several domains to access the same docker container by using Traefik. In this example I want to connect the domains whoami.example.com
and whoami.traefik-examples.tk
to the same docker container.
All necessary files are available on GitHub.
Requirements
- Two domain names that both point to the Traefik instance (in this example I use
example.com
andtraefik-examples.tk
) - For both domains the SSL certificate is generated by Let’s Encrypt
- Traefik is already working (see basic example)
Steps
- Aggiungere o modificare il
docker-compose
dei container interessati
whoami:
image: containous/whoami
container_name: whoami
labels:
- 'traefik.enable=true'
- "traefik.http.routers.whoami.rule=Host(`whoami.example.com`) || Host(`whoami.traefik-examples.tk`)" # <== edit
- 'traefik.http.routers.whoami.entrypoints=web-secure'
- 'traefik.http.routers.whoami.tls=true'
- "traefik.http.routers.whoami.tls.certresolver=certificato"
- "traefik.http.routers.whoami.tls.domains[0].main=*.example.com"
- "traefik.http.routers.whoami.tls.domains[1].main=*.traefik-examples.tk" # <== add
- Recreate the
whoami
container with the command
sudo docker-compose up -d whoami
- In the browser try to reach the site using both addresses
If you discover problems in this guide or in the configuration files, you can open an issue on GitHub. Thank you!