How do I set up a multi-site using Sitecore + Docker?

25 Feb 2021

Share on social media

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.

Pre-requisites

  • Sitecore 9.x or 10.x, with SXA +Traefik Docker image
  • Docker containers experience
  • Powershell chops


Planning your domains in docker     

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.

Multiple SSL certs

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.


Binding to Traefik

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.


Testing things out

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.

Creating a Tenant in Sitecore SXA

Create a Tenant in the Sitecore Instance and configure appropriately. Once created we can now configure our sub-domain.

  1. Go into Content Editor and click the Sitecore icon menu and select PowerShell Toolbox.

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.


Test it out!!

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.

Sign up to our newsletter


Tags:

Docker
Sitecore
SXA

Share on social media


Subscribe to newsletter