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
There are many options how to install Sitecore Experience Platform. For the very basic demo setup, we will need the following:
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:
Dockerfilein the folder we just created.
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:
docker sitecore Databases ... Website ... Data license.xml ...
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 . / WORKDIR /
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 Dockerfile:
RUN powershell ./sql.ps1 -Verbose
In the same way as for Microsoft SQL Server, setup IIS:
RUN powershell ./iis.ps1 -Verbose
Now we have all we need to build an image. Here’s our final
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!
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:
Open http://sitecore/ in a browser, it should look like this:
This is it! In the same way, we can setup Mongo and Solr.