Sitecore 9.0.2 in Windows Docker containers
In our previous post Sitecore – Meet the Dockers we showed that it is possible to run Sitecore in Docker on Mac or Windows and how to install it with Kitematic GUI.
In this post you will learn how to install a complete solution using Sitecore 9.0.2 with xConnect, Helix Habitat, MSSQL and Solr.
Probably all of you always wanted to know how to get a clean installation of Sitecore with all services and databases up and running very quick, but you know that it always takes a lot of time...
Now it is possible to have it up and running in minutes thanks to Docker. After a lot of searching and trying we finally created the docker solution that works with the latest Sitecore update 9.0.2 (rev. 180604). We have found some very good solutions like the official Sitecore + Docker github repo but there we have found out that it does not support xConnect and that it has many flaws. Then we found another great source from avivasolutionsnl where we saw that those guys already implemented xConnect with Docker and saved us some time. We have played with this solution and we saw that it also has some problems with xConnect, but it was fixable. After all we fixed the problems with xConnect and database creations, hosts in docker images, watcher services and many more and we have implemented a complete solution based on the newest Sitecore version and the new version of SIF 1.2.1.
When we realized that what we have is just a basic Sitecore without anything, we went one step further and we took the Habitat solution with the latest update packages for version 9.0.2. We implemented some more tweaks for Unicorn files export and sync in the solution and configured our Sitecore Docker container to use the Habitat solution.
After all we got it up and running without any errors in the log files.
We fixed the problem that Docker has sometime with domains and accessing the database and Solr. We implemented a Powershell script to write directly to the windows host file domains and IP addresses. In the Docker file we added new Powershell commands to run addhosts PS script "RUN /Scripts/Add-Hosts.ps1".
Preparation
In order to get your Sitecore in Docker up and running, you have to follow these steps:
- Install Docker for Windows which can be downloaded from the official Docker store.
- Enable Hyper-V.
- Enable Docker to use Windows containers.
- You can then proceed with Sitecore containers creation. You need to download the Docker files from GitHub repository
You are now ready to start playing with Docker and Sitecore 9
Build Sitecore Docker containers
Before you start with building your own Sitecore containers you should download all the necessary Sitecore installation files and place them into the files folder. Run the script for the creation of the certificates ./Generate-Certificates.ps1, and for the log folders ./CreateLogFolders.ps1.
You must run your Powershell console with Windows administrator rights and go to the folder where you placed your Docker images files. From there you can run now the Powershell command "docker-compose build" and Docker will start with downloading of the necessary files and with the creation of the MSSQL, Solr, xConnect and Sitecore containers.
When everything is built you must run "docker-compose up" to get your containers up and running.
The last step should be to update your Habitat solution Gulp and config files in order to get it work directly with your Docker containers.
To publish and run the Helix Habitat solution in your Sitecore Docker solution you have to add this script to your gulpfile.js
To your gulp-config.js file add this line
var unicornExportFolder = "C:\\docker-images\\wwwroot\\Sitecore\\Unicorn";
and change instanceRoot to
var instanceRoot = "C:\\docker-images\\wwwroot\\Sitecore";
You have to change Habitat.Dev.config to sync unicorn files from wwwroot
sc.variable name="sourceFolder" value="C:\inetpub\wwwroot\sitecore\Unicorn"
Final Steps
- Run the Habitat.sln with Visual Studio export Unicorn files by executing gulp Export-Unicorn-Files command.
- Execute Gulp Publish-All-Projects.
- Your files should be exported in your Docker images\wwwroot\sitecore folder and it should be automaticaly synced with Sitecore inside Docker.
- Now you can run gulp sync-unicorn from your solution to synchronize all Unicorn files.
- If you get problems with SSL after runing sync-unicorn than you have to tweak your \scripts\Unicorn\Unicorn.psm1 file. Add this after "Add-Type -Path $MicroCHAP" line.
Run your Habitat URL https://docker.habitat.dev.local and you will have it up and running!
Many thanks to avivasolutionsnl that saved us a lot of time and accepted some of our changes in Git pull request.