Running Sitecore in a Docker container is easier than you might think
Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries — anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.
I was looking forward to Docker support of Windows containers for a long time. Docker supports Windows containers nowadays and it means we are able to put our Windows applications in containers in order to save a lot of time spent on setting up development, testing, and deployment.
These days Microsoft gives a lot of
Dockerfile examples so setting up a container for ASP.NET web application is not a pain but a pleasure.
In this article, I am going to show how to perform a very basic setup for Sitecore Experience Platform 8.2.
To set it up, I mixed the following
- microsoft/windowsservercore — Windows Server 2016 Server Core base OS image for Windows containers.
- microsoft/mssql-server-2016-express-windows — Microsoft SQL Server 2016 Express.
- microsoft/iis — Internet Information Services (IIS).
There are many options how to install Sitecore Experience Platform. For the very basic demo setup, we will need the following:
- ZIP archive of the Sitecore site root folder.
- A Sitecore license (I hope you have got one).
- Microsoft SQL Server installer. You can get it from here (Microsoft SQL Express 2016).
- You’ll need to run Windows 10 or Windows Server 2016 on your PC or laptop.
Once you have all these, we can go further.
Follow this article to setup Docker on Windows. If you already have Docker installed, please, verify the version of
dockerd service. I have spent some time trying to figure out that the version of the
dockerd service on my machine is not the same as I just installed. Quick check – you should be able to pull Windows containers like that:
docker pull microsoft/windowsservercore
And here are the first step to start building a Sitecore container:
- Create a folder for our container (i.e.
- Create a
Dockerfilein the folder we just created.
- Start our
Dockerfileby specifying the Base Image for our container:
I put Sitecore files just in the same way as for local quick setup. The structure is like that:
I will not dive deep into Sitecore configuration. You just need to place files as you usually do when you setup your Sitecore instances. Remember about
ConnectionStrings.config and a path to
license.xml. Don't attach the databases.
Add to our
Dockerfile the following lines to make the files available in the container:
COPY . /
Now we need to set up Microsoft SQL Server. Add to the
Dockerfile a following line:
RUN SQLEXPR_x64_ENU.exe /qs /x:setup && /setup/setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT="NT AUTHORITY\System" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS && del /F /Q SQLEXPR_x64_ENU.exe && rd /q /s setup
Remember, SQLEXPR_x64_ENU.exe must be at the root of our folder, like:
Next, I run a PowerShell script to enable
sa account, change the password and attach databases. Add the following line to our
RUN powershell ./sql.ps1 -Verbose
Here is sql.ps1:
In the same way as for Microsoft SQL Server, setup IIS:
RUN powershell ./iis.ps1 -Verbose
Here is iis.ps1:
Now we have all we need to build an image. Here’s our final Dockerfile:
To build an image, let’s create a
build.bat file in our folder (
C:\docker) with following content:
docker build -t sitecore %~dp0
Run this file and wait for the build to complete. Then, if we run
docker images we shall see the
sitecoreimage. Now let's use it!
Create a container and run it
To create containers from our image run a command like this:
docker run --name sitecore -p 80:80 -it sitecore powershell
This will log you into powershell console on your Docker container. Run
ping sitecore to find an IP-address of our Sitecore instance:
Pinging 172.26.102.196 with 32 bytes of data
C:\Windows\System32\drivers\etc\hosts file a following line:
http://sitecore/ in a browser, it should lool like this:
This is it! In the same way, we can setup Mongo and Solr.
- All Sitecore Links — unfortunately, I found this website after I wrote this article. But it’s still a good source of Sitecore related topics including Docker.
- Running Sitecore 8 in a Docker Container — this article is pretty obsolete but it is still good for inspiration.
- Isolated feature testing in a Sitecore Docker Container
- How to Setup Mongo and Solr on Docker for Sitecore xDB