Sitecore Docker Containers — Auto Bind Custom Domains to your CM and CD

Mark Gibbons
May 15, 2023

If you’re developing with Sitecore on Docker and need to bind some custom domains to your CM/CD instances in Traefik, here’s an easy and future-proof way.

Naming Convention

First, I’m defining that cm.yourdomain.localhost and *-cm.yourdomain.localhost should automatically resolve to your CM container, and similarly cd.yourdomain.localhost and *-cd.yourdomain.localhost should automatically resolve to your CD container.

Update docker-compose.yml

Locate your traefik.http.routers.cm-secure.rule and traefik.http.routers.cd-secure.rule.

Update traefik.http.routers.cd-secure.rule as follows:

“traefik.http.routers.cd-secure.rule=HostRegexp(`{subdomain:([a-z]+-|)}${CD_HOST}`)”

Update traefik.http.routers.cm-secure.rule as follows:

“traefik.http.routers.cm-secure.rule=HostRegexp(`{subdomain:([a-z]+-|)}${CM_HOST}`)”

Update your init.ps1

Add your custom domains. For example:

Add-HostsEntry “custom1-cm.$($HostName).localhost”

Add-HostsEntry “custom1-cd.$($HostName).localhost”

Update <sites> configuration

If you’re not on SXA then update your <sites>, if you’re on SXA then update the Site Groupings.

Done!

--

--

Mark Gibbons

Technical Architect @ Aceik | Sitecore Technology MVP 2020 - 2024 with a love for all things #Sitecore / Twitter twitter.com/markgibbons25