Docker & Sitecore 10 - My first experience

Sitecore and Docker logos

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:
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.

  1. Open a Powershell command line with Administrator privilege
  2.  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:
  1. Open a Powershell command line with Administrator privilege
  2. Go to your solutions folder and create the MyProject solution and project:
    dotnet new sitecore.aspnet.gettingstarted -n YourProjectName
  3. Enter Y, in order to run the NuGet restore command
  4. Navigate to the newly created project folder YourProjectName
  5. 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>"
  6. Wait for the process to be finished. When all looks good, move to the next step
  7. To boot up the container run the ".\up.ps1" command

Troubleshooting

[17440] Failed to execute script docker-compose
Docker compose error

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.

ERROR: Service 'dotnetsdk' failed to build : Build failed
.NET Framework SDK error

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.

  1. Right-click the Docker Whale icon
  2. Choose "Switch to Windows containers..."
  3. 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.
  4. Wait for the process to finish. When the Docker Desktop is green again, in the lower-left corner, you're good to go.

Switching to Windows containers