My boring Blog

Mauro Frigerio blog

Multiple domains for the same container with Traefik

23-07-2022 1 min read Article

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!