Karega Anglin - Senior Sitecore Developer
25 Feb 2021
In this blog we will be looking at start to finish of setting up a Multi-site instance of Sitecore using Docker.
Most companies host multiple domains for their business (e.g. email.domain.com, ftp.domain.com,shop.domain1.com … etc.), and this happens over time as the company grows and requirements change. It is common to host multiple websites on a single instance of Sitecore, whether that is a subdomain or a completely different domain such as when hosting separate websites for different product brands. These businesses know they will need xyz.domain.com and know the logistics surrounding it. I would like to demo for the latter companies, how to setup a multi-site instance of Sitecore on Docker using SXA.
To start adding the domains, we utilize the facility of the docker .env file, to setup our domains as environment variables.
Here we added CM_DOMAINS to the .env file. Note: that the CM_HOST is cm.xyz.localho.st, and this could be any host name that your instance lives under. However the domain *.localho.st is used for the sub-domains in CM_DOMAINS. Again, the domains could be whatever you plan for, e.g. ftp.localho.st or website.localho.st.
Next we need to let mkcert tool generate a cert for multiple domains instead of a single domain. To accomplish this we simply modify the PowerShell script, encapsulating the mkcert tool and send in multiple command-line parameters for the certificate generation (documented here)
This will generate a certificate for the Sitecore instance using the main in *.$(FullHostName) and *localho.st as domains.
Next up, we added the domains to Traefik for routing. We added the domains to the docker-compose.override.yml file to extend the main compose file ( https://docs.docker.com/compose/extends/ ).
Sitecore interacts with Traefik using docker container labels ( https://doc.traefik.io/traefik/providers/docker/#routing-configuration-with-labels ). This will then add another route into Traefik, to let it know how to handle requests coming to the domains. The route "cm-alternate" labeling was used for a cleaner representation in the docker compose file, so debugging issues is easier. We can check our final merged compose file using the "docker-compose config" command to see how everything comes together.
Finally we can now test our domains. Save all and do a "docker-compose up" for the main Sitecore instance, then navigate to the sub-domains.
All looks good! The sub-domains are routing back the main instance, which is exactly what we want to see.
Next we can start building out our sub-domain sites in SXA.
Create a Tenant in the Sitecore Instance and configure appropriately. Once created we can now configure our sub-domain.
2. This will open up the PowerShell Extension Menu, and we select the SXA Site Manager.
3. We select the edit the SXA Tenant site and add the sub-domain into the "Host Name" field, save and publish.
Now that we configured the SXA Site, lets navigate to the domain as before.
Here we demonstrated how to configure and spin up a multi-site instance of Sitecore with SXA on Docker. This adds an easy way of spinning up a well mapped out sub-domain hierarchy on a single instance and get you up and running in no time with no changes to the Sitecore configuration files needed.
With over 7 years experience specializing in the Sitecore CMS platform, and more than 10 years in Applications Development, Karega has helped to implement and maintain several high-profile organization websites such as Toronto Transit Commission, Sick Kids Foundation and Ontario College of Teachers. He holds a MSc in Computer Science from the University of the West Indies Jamaica and certifications in both Sitecore CMS .NET and Machine Learning (Coursera).
When not creating software, Karega engages in ministry at his local church and social programs in his community. He is also plays the Bass and Electric Guitar and is inspired by musical the genres such as Gospel, Jazz, Retro/Funk and Latin.
Karega can often be found learning the next new thing in Software development and Artificial Intelligence and believes strongly in always keeping tabs on emerging Tech for the benefit of Society.
Share on social media