This week I started looking into the world of Sitecore XP 10 and Docker. I'm not new to the whole containerization that is taking place nowadays. I've been using it for a couple of years in development. But never got the hang of it. I understand the possible benefits of working with such a solution, but it also has its downsides. Especially when moving from a development machine to a scalable cloud solution.
Back to Sitecore this time. As more and more software is moving to the cloud as a Software-as-a-Service also known as SaaS applications, this step by Sitecore I think is an in-between step. It will help existing on-prem customers to move more easily into the SaaS concept in the future.
So how do you get started with Docker and Sitecore XP 10?
Luckily, Sitecore has some good documentation about this on their website. Before you can start you need to make sure that you've the following prerequisites installed:
- Sitecore license file
- .NET Core 3.1 SDK (check your installed version with the dotnet --version command)
- .NET Framework 4.8 SDK (see the Microsoft procedure for checking .NET Framework versions)
- Visual Studio 2019
- Docker for Windows (with Windows Containers enabled)
- PowerShell 5.1 (PowerShell 7 is not supported)
- Make sure to allow unrestricted scripts to be executed with Powershell
Set-ExecutionPolicy Unrestricted
How to get the Docker and Visual Studio template?
Sitecore has fully prepped a Docker and Visual Studio into a template. All we need to do is download it in order to be able to make changes to it.
- Open a Powershell command line with Administrator privilege
- Run the following command
dotnet new -i Sitecore.DevEx.Templates --nuget-source https://sitecore.myget.org/F/sc-packages/api/v3/index.json
After the template has finished installation move to the next step.
Create your First project
Now that we have our template downloaded and installed, we can create a new project based on the template. To create a new project execute the following steps:
- Open a Powershell command line with Administrator privilege
- Go to your solutions folder and create the MyProject solution and project:
dotnet new sitecore.aspnet.gettingstarted -n YourProjectName - Enter Y, in order to run the NuGet restore command
- Navigate to the newly created project folder YourProjectName
- To prepare the Sitecore container environment, run the following command:
.\init.ps1 -InitEnv -LicenseXmlPath "<path to your license.xml file>" -AdminPassword "<your Sitecore administrator password>" - Wait for the process to be finished. When all looks good, move to the next step
- To boot up the container run the ".\up.ps1" command
Troubleshooting
[17440] Failed to execute script docker-compose
When you get this error, be sure to start the Docker Desktop and retry the init command. When starting Docker Desktop, wait for the process to be completed upon retrying.
The docker instance can find any dotnet SDK on the host operating system. Don't be fooled like I was when using the WSL (Windows Sub Linux) system, you can now fully run Linux containers on a Windows OS. But here comes the caveat, Sitecore can't do this. It's still dependent on Windows due to the .NET Framework 4.8 programs. In order to fix this error, you should move to Windows containers.
- Right-click the Docker Whale icon
- Choose "Switch to Windows containers..."
- Hit "Switch"
If the process fails, let Docker Desktop restart itself and retry. The reason why Docker may crash, is that it has active containers running in the background. Don't worry about it and just retry. - Wait for the process to finish. When the Docker Desktop is green again, in the lower-left corner, you're good to go.