Dear Sitecorians, I hope you all have a wonderful time π
First of all to all new and old Sitecore MVPs – CONGRATULATIONS!!
Secondly, don’t forget to book for SUGCON Europe 2020.
The agenda looks really interesting, https://europe.sugcon.events/Agenda
Today’s post will be about… DOCKERS. The never-ending flow of the wonderful Sitecore Docker Images.
*Guess which session I will be at(in SUGCON Europe 2020), this one of course π
I would like to share with you guys a very cool way of working with Sitecore Docker containers – Using the Docker Compose project(dcproj) together with the “Container” window in Visual Studio, it’s just awesome!!
They all love it, check out Scott Hanselman’s post: Trying out Container Tools in Visual Studio 2019
So what is Docker Compose?
When you want to compose a multi-container solution using Docker Compose, add container orchestration support to your projects. This lets you run and debug a group of containers (a whole solution or group of projects) at the same time if they’re defined in the same docker-compose.yml fil
You can read all about it here, Container Tools in Visual Studio
So first we need to create a new project in our lovely Helix Sandbox Solution, as always we will use the best ever sandbox solution – Helix.Examples. You can find all the work in my fork: https://github.com/GoranHalvarsson/Helix.Examples/tree/master/examples/helix-basic-tds-with-docker-vs2019-project-type
If we were working in Asp.Net Core, then it would be quite easy to create a DockerCompose project(.dcproj):
Unfortunately we are still in Asp.Net Framework π¦
*We can at least find comfort in using the new project type in our projects π
Instead, we will create the project manually. We will switch to folder view in our solution(no need to use the File Explorer) and navigate to the src folder in folder helix-basic-tds-with-docker-vs2019-project-type. Here we will create a DockerCompose folder. Right click and create the following files:
– docker-compose.dcproj => project
– .env => The environment variables for the docker-compose file
– docker-compose.yml => docker-compose file
– docker-compose.override.yml => docker-compose file
For the docker-compose.dcproj, we will add the following:
<Project Sdk="Microsoft.Docker.Sdk"> <PropertyGroup Label="Globals"> <ProjectGuid>e7832a11-26ec-4ab3-99d8-4db5d9c689eb</ProjectGuid> </PropertyGroup> <PropertyGroup> <ProjectVersion>2.1</ProjectVersion> <DockerTargetOS>Windows</DockerTargetOS> </PropertyGroup> <ItemGroup> <None Include=".env" /> <None Include="docker-compose.override.yml"> <DependentUpon>docker-compose.yml</DependentUpon> </None> <None Include="docker-compose.yml" /> </ItemGroup> </Project>
The .env file will be the same as before:
REGISTRY=sitecoreimages.azurecr.io/ WINDOWSSERVERCORE_VERSION=1903 NANOSERVER_VERSION=1903 SITECORE_VERSION=9.3.0 SITECORE_LICENSE= REMOTEDEBUGGER_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Remote Debugger SQL_SA_PASSWORD=8Tombs-Given-Clock#-arming-Alva-debut-Spine-monica-Normal-Ted-About1-chard-Easily-granddad-5Context! TELERIK_ENCRYPTION_KEY=qspJhcSmT5VQSfbZadFfzhCK6Ud7uRoS42Qcm8UofvVLiXciUBcUeZELsTo8KD9o6KderQr9Z8uZ9CHisFJNRz46WTZ5qCRufRFt
For the docker-compose.yml, we will do some minor path changes for the data folder(Located in helix-basic-tds-with-docker-vs2019-project-type/Docker)
version: '2.4' services: sql: image: ${REGISTRY}sitecore-xp-spe-sqldev:${SITECORE_VERSION}-windowsservercore-${WINDOWSSERVERCORE_VERSION} volumes: - ..\..\Docker\data\sql:C:\Data mem_limit: 2GB ports: - "44010:1433" environment: SA_PASSWORD: ${SQL_SA_PASSWORD} ACCEPT_EULA: "Y" - - -
For the docker-compose.override.yml, just add the version for now:
version: '2.4'
Next will be to switch back to the “Solution view”(in Visual Studio) and add the new project we created – docker-compose.dcproj.
And voila, we have a Docker Compose project π
One thing is needed before we run the Docker Compose project, we need to execute Set-LicenseEnvironmentVariable.ps1 script in our Docker folder(C:\Projects\Helix.Examples\examples\helix-basic-tds-with-docker-vs2019-project-type\Docker):
.\Set-LicenseEnvironmentVariable.ps1 -Path C:\license\license.xml -PersistForCurrentUser
Finally, set the Docker Compose project as StartUp Project and hit Docker Compose π
To add the Container Window, just do View=> Other Windows=> Containers:
The Container tool is great, you can check Logs, Ports and Files:
And you can open up a Terminal Window to your favorite container, like this:
This is pretty awesome!
There is one thing left and that is to run it in debug mode “directly” when we hit “Docker Compose”. For now, we still have to attach the debugger. Meaning we need to get the IP address from the container and all that annoying stuff. I have been experimenting with adding a Docker file to the BasicCompany.Project.BasicCompany project but still no success… π¦
ARG BASE_IMAGE FROM $BASE_IMAGE as build .... do some stuff
And then in the docker-compose file something like this:
cm: build: context: .\..\Project\BasicCompany\website dockerfile: .\..\Project\BasicCompany\website\dockerfile args: BASE_IMAGE: sitecoreimages.azurecr.io/sitecore-xp-spe-standalone:9.3.0-windowsservercore-1903 - - -
I will keep on trying until I find a solution…
It would be great if you guys could help out!
Fork my fork and start coding π
https://github.com/GoranHalvarsson/Helix.Examples/tree/master/examples/helix-basic-tds-with-docker-vs2019-project-type
Think how neat it would be, to just set the Docker Compose project as Startup and hit F5. No more attaching a debugger and all that…
Thatβs all for now folks π