Sitecore Docker Multi-Site Configuration: A Developer’s Guide

     Sitecore's Docker support has revolutionized local development, making it easier to spin up isolated environments. But when it comes to multi-site development.

In this blog, we’ll walk through the end-to-end process of adding a new site to your Sitecore Docker instance.

Steps to Setup the new site

1. Define Your New Site Domain

Decide on a domain for your new site. For local development, use something like:

                    Newsite.localhost

Also create Site node in Sitecore content tree and add the site configuration under sites in configuration. I'm not covering this information in detail and as this is a regular process.

2. Update .env File

Add your new domain to the HOSTNAME,TARGETHOSTNAME,TARGETWEBHOSTNAME for both CM and CD sites.

    cm.newsite.localhost

    cd.newsite.localhost

3. Update docker-compose.yml

  • In Identity Server node, Under environment add below entry for CORS 
   id:
   environment:

Sitecore_Sitecore__IdentityServer__Clients__DefaultClient__AllowedCorsOrigins__AllowedCorsOriginsGroup1: https://cm.newsite.localhost      

  • In CM node, add the domain name and traefik configuration.

     cm:
      environment:
        CM.HostName: cm.newsite.localhost
        CM.targetHostName: cm.newsite.localhost
        CM.targetWebHostName: cd.newsite.localhost
      labels:
        "traefik.http.routers.cm-secure.rule=Host(`${CM_HOST}`)||Host(`cm.newsite.localhost`)"    
  • In CD node, add the domain name and traefik configuration.

     cd:
      environment:
        CD.HostName: cd.newsite.localhost
        CD.targetHostName: cd.newsite.localhost
      labels:
        "traefik.http.routers.cm-secure.rule=Host(`${CD_HOST}`)||Host(`cd.newsite.localhost`)"    
        This tells Traefik to route these domains into container

4. Generate SSL Certificates


I have created a script which helps to create a new domain in Sitecore Docker Instance and adds environment varibles in.env file, creates and push certificates in docker file path and also adds domain entries in the local development environment host file.

        Here is the Link for my Gist File : Docker-Cert Setup.ps1, refer this for script and update as per your need.

       After the above step, need to navigate to docker/traefik/config/dynamic/certs_config.yaml file and do the following update.

    tls:
      certificates:
        - certFile: C:\etc\traefik\certs\_wildcard.newsite.localhost.pem
          keyFile: C:\etc\traefik\certs\_wildcard.newsite.localhost-key.pem
    

5. Restart Docker Containers

    Rebuild and restart your containers to apply changes:

        docker-compose down
        docker-compose up -d

6. Create a New Site in Sitecore
  • Log in to Sitecore 
  • Navigate to Content Editor
  • Under /sitecore/Content create a new site
  • Also create required media, content and layouts

7. Configure Hostname in Sitecore

        
        Create a new Site config and all the required entries under /App_config

8. Publish and Test

  • Publish the entire site (content + media + layouts)
  • Open https://newsite.localhost in your browser

🏁 Conclusion

Adding a new site in a Sitecore Docker instance is straightforward once you understand the moving parts - Traefik routing,  site creation, Certificate and hostname configuration. With this setup, you can scale your local environment to support multiple sites with ease.

Happy Dockering 😀😀

Comments