Skip to main content
Multiple domains for the same container with Traefik
  1. Articles/

Multiple domains for the same container with Traefik

·1 min
Article Traefik Diy Bricolage
Table of Contents

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
#

  1. Two domain names that both point to the Traefik instance (in this example I use example.com and traefik-examples.tk)
  2. For both domains the SSL certificate is generated by Let’s Encrypt
  3. Traefik is already working (see basic example)

Steps
#

  1. 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
  1. Recreate the whoami container with the command
sudo docker-compose up -d whoami
  1. 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!

Related

SSO and 2FA for Traefik and Docker containers
·2 mins
Article Traefik Diy Bricolage
Traefik 2.x examples
·2 mins
Article Traefik Diy Bricolage
Secondary home management experience with Home Assistant
·4 mins
Article Diy Bricolage Iot Home Smart-Home VPN Wireguard Home Assistant