How to Running Sitefinity from a Docker Container

How to Running Sitefinity from a Docker Container

CheapASPNETHostingReview.com | Best and cheap Sitefinity Hosting. 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:

dc SitefinityLogo_woTagline_RGB-1024x433

Prerequisites

  • 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.  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:

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:

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:

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:

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

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

And finally run the DSC configuration:

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:

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:

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:

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/.