Try Now
More in this section
Blogs RSS feed

Containerize This: Running Sitefinity from a Docker Container

by Radoslav Georgiev

Since Microsoft announced support for containers in the next version of Windows Server (Windows Server 2016) I've been eager to find out if we can run Sitefinity from a container on that OS. The short answer is yes, we can containerize Sitefinity applications and run them on container hosts. This blog post will cover a proof of concept that shows Sitefinity can be containerized and is is influenced by this guide on running Docker containers: Windows Containers Quick Start - Docker


  • Sitefinity project connected to a database. For this setup, I have chosen SQL Azure database
  • Windows Container Host running Windows Server 2016 Core. For the purposes of this demo I will be using a VM created on Azure with the Windows Server 2016 Core with Containers Tech Preview 4 image

Let's roll up our sleeves

If you will be using a container host on Azure, create it and you are ready to go. If you have decided to explore this locally, please check out this article: Deploy a Windows Container Host to a New Hyper-V Virtual Machine. The Azure container host image comes with Docker pre-installed so you will have some base images to start from. In the command line run the following command:

C:\>docker images

This should return the list of available images:

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
windowsservercore   latest              6801d964fda5        3 weeks ago         0 B
windowsservercore   10.0.10586.0        6801d964fda5        3 weeks ago         0 B

Creating Docker container image

For the sake of simplicity we will create the image by running a new container and then committing the changes applied to it in a new image. To create a new Docker container and instantiate a new Powershell session, run the following command:

C:\>docker run --name sfcntnr -it windowsservercore powershell

Once the container is instantiated and our Powershell session has started we need to configure the container to host our Sitefinity website. To achieve this we will use Powershell DSC to install all necessary Windows features and configure our website in IIS. I have prepared a sample DSC configuration and configuration data in this GitHub repo: sf-cntnr-poc. The dsc/sfwebapp.ps1 file contains the necessary configuration and dsc/sfwebapp-data.psd1 contains the variables (Windows feature, URL from which to download the website, etc.). Since I am working in Azure and I do not have access to my local computer, I have zipped my website and uploaded it to Azure Blob. This will serve as the source of my website. If you are using the same approach edit the dsc/sfwebapp-data.psd1 file to point it to the proper URL:

SitefinityWebAppSource = "YourWebsiteArchiveURL"

Once you make the necessary changes to those files to reflect your setup you can upload them to Azure blob as well so that they can be downloaded on the Docker container. The DSC configuration uses some community modules to set up our website, so before we apply the configuration we need to download those modules. In the Powershell session of your Docker container run the following commands to install the modules:

PS C:\Windows\system32> Install-Module -Name xWebAdministration -Force
PS C:\Windows\system32> Install-Module -Name xPSDesiredStateConfiguration -Force
PS C:\Windows\system32> Install-Module -Name cNtfsAccessControl -Force

Once this is done let’s get the DSC configuration and data files from our blob:

PS C:\Windows\system32> wget -uri URLToTheFile -outfile C:\sfwebapp.ps1
PS C:\Windows\system32> wget -uri URLToTheFile -outfile C:\sfwebapp-data.psd1

At this point we are ready to configure our container with everything necessary to host a Sitefinity website. First let’s prepare the DSC configuration:

PS C:\Windows\system32> . C:\sfwebapp.ps1
PS C:\Windows\system32> SitefinityWebApp -ConfigurationData C:\sfwebapp-data.psd1 -OutputPath C:\

And finally run the DSC configuration:

PS C:\Windows\system32> Start-DscConfiguration -Path C:\ -Wait -Verbose

Now get a cup of coffee and wait for the configuration changes to be applied. After the configuration is applied the container will be ready to run a Sitefinity site, however, we need to take care of some firewall settings so that requests can reach the IIS in the container. So let's exit the container and capture our image:

PS C:\Windows\system32> exit
C:\> docker commit sfcntnr sfcntnr

Opening ports on the firewall

When the commit command is ready you will be able to see your new Docker image in the images list. What is left now is to open the necessary firewall ports, expose port 80 from the Azure management portal, and run our new container. First, to make sure that the Windows firewall is allowing port 80, run the following Powershell command:

if (!(Get-NetFirewallRule | where {$_.Name -eq "TCP80"})) {
    New-NetFirewallRule -Name "TCP80" -DisplayName "HTTP on TCP/80" -Protocol tcp -LocalPort 80 -Action Allow -Enabled True

Running your containerized site

After you create the necessary endpoint in the Azure management portal all you are left to do is to run the container using the following command:

C:\> docker run --name mysite -it -p 80:80 sfcntnr powershell

When the container is ready, the site will be accessed by the outside world using the domain name assigned to the Azure VM, e.g. http://sfcntnr1.cloudapp.net/.

Leave a comment