Building a Sitecore Solution from Scratch with Docker: Part 2
- Gowtham
- Apr 10, 2023
- 4 min read
Updated: May 18, 2023
In our previous post, we discussed the installation of Docker using the default template which utilizes the Sitecore XP0 topology. In this blog post, we will update the folder structure to align with Helix principles, which will assist us in building our solution using the Helix methodology. Furthermore, we will use the XM topology for ease of implementation.
Updating the folder structure
In order to align with Helix guidelines, we will update the folder structure and adjust file paths as required. You can refer to Sitecore's official Helix principles to ensure compliance with industry standards.
Create a new folder named "docker" and a subfolder named "data". Rename the "mssql-data" folder to "mssql", "device-detection" folder to "devicedetection" and the "solr-data" folder to "solr", and then move both folders into the "data" subfolder that you created.

Move the "traefik" folder to the "docker" folder and the "docker" folder structure will be similar to the following.

Update the configuration files
Updating Clean.ps1
Now that we have updated the folder structure, we must also update our configuration files accordingly. Let's begin by updating the "Clean.ps1" script as shown below to reflect the new folder structure.
# Clean data folders
Get-ChildItem -Path (Join-Path $PSScriptRoot "\docker\data\mssql") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Get-ChildItem -Path (Join-Path $PSScriptRoot "\docker\data\solr") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Get-ChildItem -Path (Join-Path $PSScriptRoot "\docker\data\cd") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Get-ChildItem -Path (Join-Path $PSScriptRoot "\docker\data\cm") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Get-ChildItem -Path (Join-Path $PSScriptRoot "\docker\data\devicedetection") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Get-ChildItem -Path (Join-Path $PSScriptRoot "\docker\traefik\certs") -Exclude ".gitkeep" -Recurse | Remove-Item -Force -Recurse -Verbose
Updating .env file
As previously mentioned, we will be implementing the XM topology. Therefore, we must add/update certain variables in the ".env" file. Please update the variables listed below in the ".env" file.
COMPOSE_PROJECT_NAME=sitecoredocker
CD_HOST=cd.sitecoredocker.localhost
CM_HOST=cm.sitecoredocker.localhost
ID_HOST=id.sitecoredocker.localhost
LOCAL_DEPLOY_PATH=.\docker\deploy
LOCAL_DATA_PATH=.\docker\data
Update the Hostname in init.ps1
Now that we have updated the domain names, it is necessary to modify the locations where we generate the SSL certificate and assign them to the corresponding sites.
Open the "certs_config.yaml" file located at "\docker\traefik\config\dynamic" and replace the contents with the following.
tls:
certificates:
- certFile: C:\etc\traefik\certs\cert.pem
keyFile: C:\etc\traefik\certs\key.pem
Navigate to the root folder and open ".init.ps1" file. Search for the relevant section and replace the contents with the following code:
from
Write-Host "Generating Traefik TLS certificates..." -ForegroundColor Green
& $mkcert -install
& $mkcert -cert-file xp0cm.localhost.crt -key-file xp0cm.localhost.key "xp0cm.localhost"
& $mkcert -cert-file xp0id.localhost.crt -key-file xp0id.localhost.key "xp0id.localhost"
to
Write-Host "Generating Traefik TLS certificate..." -ForegroundColor Green
& $mkcert -install
& $mkcert -key-file key.pem -cert-file cert.pem "*.$($HostName).localhost"
In the same file at the bottom, you will find the following code that adds the domains to the host entry.
Add-HostsEntry "xp0cm.localhost"
Add-HostsEntry "xp0id.localhost"
Replace the previously mentioned code with the following code snippet.
Add-HostsEntry "cd.$($HostName).localhost"
Add-HostsEntry "cm.$($HostName).localhost"
Add-HostsEntry "id.$($HostName).localhost"
Search for the below code in the current file
Push-Location traefik\certs
Replace it with
Push-Location docker\traefik\certs
On the Param variables add the below line
[string]
$HostName = "sitecoredocker",
Updating docker-compose and creating new files for XM1 topology
So far, we have been using the default "docker-compose.yml" file for XP0 topology. However, we need to switch to the XM1 topology by using a different docker compose file. You can download the XM1 docker compose file from here and replace it with your current configuration.
Create a new file called "docker-compose.override.yml". The "docker-compose.override.yml" file is a configuration file that is used to override or extend the services defined in the base "docker-compose.yml".
Traefik
We will start by configuring the Traefik service in the "docker-compose.override.yml" file. We will mount the "traefik" folder from the root "./traefik" to "C:/etc/traefik" in our Docker image. Since we have updated the folder structure, we need to override this value to point to our new structure.
version: "2.4"
services:
traefik:
volumes:
- ./docker/traefik:C:/etc/traefik
Redis
To install Redis for managing user sessions, we must update the "docker-compose.override.yml" file and create a corresponding Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
To include Redis in our setup, add the following code snippet to the "docker-compose.override.yml" file.
redis:
image: ${REGISTRY}${COMPOSE_PROJECT_NAME}-redis:${VERSION:-latest}
build:
context: ./docker/build/redis
args:
BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-redis:${SITECORE_VERSION}
Create a new folder named "build" inside the "docker" folder, and then create a new folder called "redis" inside the "build" folder. Inside the "redis" folder, create a file named "Dockerfile" and add the following code to it.
# escape=`
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

mssql-init and Solr
Inside the "build" folder, we will create two new folders called "mssql-init and solr-init". We will then create a DockerFile inside the "mssql-init and solr-init" folder with the same content as the Redis DockerFile.

After creating the files and folders, the next step is to insert the following code snippet into the docker-compose-override.yml file. This code snippet will help us to load the Solr and mssql images, which are necessary for running our basic XM site. Additionally, it will also assist us in mounting the data folder.
mssql:
mem_limit: 2GB
volumes:
- ${LOCAL_DATA_PATH}\mssql:c:\data
mssql-init:
image: ${REGISTRY}${COMPOSE_PROJECT_NAME}-xm1-mssql:${VERSION:-latest}
build:
context: ./docker/build/mssql-init
args:
BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-xm1-mssql-init:${SITECORE_VERSION}
# Mount our Solr data folder.
solr:
volumes:
- ${LOCAL_DATA_PATH}\solr:c:\data
# Mount our Solr data folder and use our retagged Solr image.
# Some modules (like SXA) also require additions to the Solr image.
solr-init:
image: ${REGISTRY}${COMPOSE_PROJECT_NAME}-xm1-solr-init:${VERSION:-latest}
build:
context: ./docker/build/solr-init
args:
BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-xm1-solr-init:${SITECORE_VERSION}
To ensure the above configuration changes not impacting to anything we confirm by running the below command.
.\init.ps1 -LicenseXmlPath "<your licensepath here>"
docker-compose up -d
The upcoming blog post will guide you on integrating Sitecore custom modules into our website, and demonstrate how to build a solution and deploy the changes from our solution to the containerized site.
Comments