Sitecore, Sitecore on Docker

Apply .xdt transforms in Dockerized Sitecore

Hello, Sitecore devs!

Recently I got a chance to work on a Sitecore project where the local development environment is on Docker. We set up the project with Sitecore 10.1 on Docker and started the development work. At one level we stuck up with the configuration file changes required to apply during the docker image build. We all know that the .xdt transforms are the best approach to apply the web configuration changes.

When we work with a normal setup, the Visual Studio takes care to apply the .xdt transforms in the respective configuration file. But things are different when we work with the dockerized environment.

I accepted that challenge to set up the docker environment which takes care of the .xdt files while building the CM image and applies the changes to the respective confirmation files.

With the successful execution of the task, I thought to share the knowledge with you guys to save your time.

Here we go now…

Reference: Please refer to the Github repo for the files mentioned in this article.

Initially, I tried a lot of options to apply the .xdt transforms based on the Sitecore documentation Applying configuration transforms (

However, those were not meeting the requirements for my project, and then I through to think outside the box to meet the challenge.

After some permutations and combinations, I found the best option to apply the transformations with help of the PowerShell script.

Following is the PowerShell script which I prepared to apply the .xdt transformations.

sc-docker-coveo/manage-xdt-transform-files.ps1 at master · iamjatinprajapati/sc-docker-coveo (

Though the transformations are required only for the local development environment and for the production environment the DevOps team was there to take care of it, I prepare the above script to apply it for any environment.

The PowerShell script takes the SC_ENVIRONMENT as the environment variable for the running context while building the CM image.

From the Dockerfile for the CM role, the above-mentioned PowerShell script is copied into the container and then executed to apply the transformations.

Here, while creating the .xdt transformation file, I followed a naming convention like web.config-local.xdt/web.config-uat.xdt/web.config-stage.xdt. Here in the file name the local/uat/stage represents the environment and that value is similar to the SC_ENVIRONMENT variable.

While executing the PowerShell script, first all the unnecessary files which are not related to the current context environment are deleted. Then the remaining .xdt files are renamed to match the actual configuration file name to apply the transformations.

Rest the transformations are applied using the Invoke-XdtTransform.ps1 script which is provided by the Sitecore tools image.

In the same way, we applied transformations in the CD image as well.

I hope this article will help you to understand how to apply the .xdt transforms in dockerized Sitecore projects.

Thanks for reading…