Sitecore Quicktip: Custom Domains and Certificates in Sitecore Docker
For those who leverage Sitecore Docker for local development, there may be a desire to have a custom domain name and corresponding certificate for your URLs. This makes it easier to distinguish between environments in case you are running multiple for local development (ex. multiple clients or differing Sitecore solutions).
Use the following steps, with particular attention to the modification of the compose-init.ps1 and certs_config.yaml files:
1. Download Docker Desktop for Windows and follow the instructions: Install Docker Desktop on Windows | Docker Documentation
2. Switch to Windows containers (note this may require enabling Hyper-V): Frequently asked questions for Windows | Docker Documentation
3. Download the “Container Deployment Package” from Sitecore Downloads for the version you want to develop in (ex. 10.2): Sitecore Downloads: Sitecore Experience Platform 102
4. Extract the Zip file and copy out the desired topology to the desired directory (ex. xm1)
5. Obtain a Sitecore license file and copy this into the root of your Docker files directory (ex. clientname>xm1)
6. Open and edit the compose-init.ps1 and change the following values to set your custom domain name. In this example I kept the topology variable and prefaced it with clientname1. Note that I am using the xm1 topology, so in other topologies such as xp1 and xp0 there will less or more host variables:
[string]
$CdHost = "clientname1$($Topology)cd.localhost",
[string]
$CmHost = "clientname1$($Topology)cm.localhost",
[string]
$IdHost = "clientname1$($Topology)id.localhost",
7. Edit the certs_config.yaml (example: .\xm1\traefik\config\dynamic\certs_config.yaml) to ensure the cert names match your host names:
tls:
certificates:
- certFile: C:\etc\traefik\certs\clientname1xm1cd.localhost.crt
keyFile: C:\etc\traefik\certs\clientname1xm1cd.localhost.key
- certFile: C:\etc\traefik\certs\clientname1xm1cm.localhost.crt
keyFile: C:\etc\traefik\certs\clientname1xm1cm.localhost.key
- certFile: C:\etc\traefik\certs\clientname1xm1id.localhost.crt
keyFile: C:\etc\traefik\certs\clientname1xm1id.localhost.key
8. Run the compose-init.ps1 including the path to the license. Note that in PowerShell I have changed directories to the C:\Users\me\Documents\Containers\10.2\clientname\xm1 directory before running this file:
.\compose-init.ps1 -LicenseXmlPath C:\Users\me\Documents\Containers\10.2\clientname1\xm1\license.xml
9. Run the following command to download images and start your Sitecore Docker environment. Note that the -d command will download and extract images on the first run, so on first run it will be longer, and without the -d in subsequent runs you will see a full logged output:
docker-compose up -d
10. When complete with your development, stop the Sitecore Docker environment via the following (you can always run the compose-docker up -d command again when you are ready to restart work):
docker-compose down