More in this section
Categories
Bloggers
Blogs RSS feed

Sitefinity in a Container in 9 Easy Steps

by The Progress Team
Sitefinity with Docker-1

If you are a professional working with Microsoft related technologies you probably have heard the new big thing in Windows Server 2016 – Windows Containers. It seems like the world of software application development is inevitably moving in that direction. Even though the technology is relatively new in the Microsoft world it is worth taking the time to play around with what we’ve got so far and analyze the potential.

As a Sitefinity developer there’s always the question of whether such a complex application that utilizes many technologies from a large timespan will be able to run in a container. And if it does – does it really bring any benefits? This is what we want to find out here.

TL;DR Yes, you can run Sitefinity in a container.

The Benefit of Containers

A container in Windows 10 is a special feature of the OS that isolates an application from the current state of the OS itself and gives an isolated view of that OS to the application that runs in the container. For example – Windows 10 and Server 2016 under the hood are basically two different distros of the same OS kernel, much like most of the Linux distros are actually based on the same Linux kernel. This means that a container that runs in a Windows 10 Client OS can fool the application running in it into thinking that it is actually running on Windows Server 2016.

All the libraries, extensions and settings that are specific to Windows Server 2016 are stored in a container image that is used together with the same kernel of the host OS to provide the same environment the application would have if it was genuinely running on a machine with Windows Server installed. This means that unlike virtual machines, container images do not need to store the entire OS, so they can be created and destroyed faster and take up less space. You could have hundreds of containers that run based on the same image—the image is not copied each time, rather only the different changes made to it are stored for each container. This translates to an even smaller disk usage footprint. You can read a more detailed explanation on the Microsoft website.

The graphic below shows a comparison between the hardware resource needed to run three applications on one server using hypervisor, and what’s needed to run the applications on the same hardware utilizing containers (in this case Docker).

Notice that the hypervisor needs to run three separate operating systems on which to host the applications. This is a lot of overhead that is not needed with containers.

The height of the graphic refers to how much resources are needed to run the applications. It is evident that when utilizing containers, the resource usage is significantly lower. This means many more applications can be ran on a single machine, utilizing a company’s hardware resources much more efficiently.

Sitefinity with Docker-2

Setting up Sitefinity in a Docker Container

 

Sitefinity with Docker-3

We already know the technical advantages of a container, and now the next step is to run Sitefinity in one, so that our favorite web content management system can leverage the benefits in full. Below we will outline how to achieve this goal in nine steps.

Now it’s the fun part – let’s setup Sitefinity to run in a Docker container.

1.       Install Docker for Windows, referring to the official documentation.

Note: make sure to check the What to know before you install section of the above documentation to avoid any issues.

2.       After a successful installation, switch Docker to use Windows containers as described here. Alright, now we have docker running with windows containers.

3.       The next step is downloading a Docker image with the operating system that we will use to host the site on. The Docker OS image that will be used to create the environment for Sitefinity is microsoft/aspnet. The image comes with different variants, and for this blog we will use:

4.7.1-windowsservercore-ltsc2016, 4.7.1, latest.

 

The docker pull command for this image is :

docker pull microsoft/aspnet:4.7.1-windowsservercore-ltsc2016

Sitefinity with Docker-4

4.       Next we prepare the Sitefinity site files for deployment to a Docker container. There are a few specifics that must be done in Sitefinity in order to deploy it in a container.

4.1. In web.config add defaultLanguage="C#" to the <compilation> section

<compilation debug="false" targetFramework="4.5" defaultLanguage="C#"

This is needed because by default ASP.NET has Visual Basic as the default compiler, and when running Sitefinity in a container it can’t detect that the default compiler must be C#.

5.       Prepare the "DockerFile".

Refer to the DockerFile sample below:

# escape=`

 

FROM microsoft/aspnet:4.7.1-windowsservercore-ltsc2016

 

COPY iis_setup.1.ps1 /

RUN c:\iis_setup.1.ps1

RUN Remove-Item -Recurse C:\inetpub\wwwroot\*

COPY . C:\inetpub\wwwroot\

 

COPY permissions.ps1 /

RUN c:\permissions.ps1

 

The DockerFile goes hand in hand with a PowerShell script that will configure the OS in the image to enable the Windows features needed by Sitefinity.

5.1   Create PowerShell file iis_setup.1.ps1 to enable the needed OS features using the code below:

Import-Module ServerManager

Add-WindowsFeature "FileAndStorage-Services";

Add-WindowsFeature "Storage-Services";

Add-WindowsFeature "Web-Server";

Add-WindowsFeature "Web-WebServer";

Add-WindowsFeature "Web-Common-Http";

Add-WindowsFeature "Web-Default-Doc";

Add-WindowsFeature "Web-Dir-Browsing";

Add-WindowsFeature "Web-Http-Errors";

Add-WindowsFeature "Web-Static-Content";

Add-WindowsFeature "Web-Health";

Add-WindowsFeature "Web-Http-Logging";

Add-WindowsFeature "Web-Request-Monitor";

Add-WindowsFeature "Web-Performance";

Add-WindowsFeature "Web-Stat-Compression";

Add-WindowsFeature "Web-Security";

Add-WindowsFeature "Web-Filtering";

Add-WindowsFeature "Web-App-Dev";

Add-WindowsFeature "Web-Net-Ext45";

Add-WindowsFeature "Web-Asp-Net45";

Add-WindowsFeature "Web-ISAPI-Ext";

Add-WindowsFeature "Web-ISAPI-Filter";

Add-WindowsFeature "Web-Mgmt-Tools";

Add-WindowsFeature "Web-Scripting-Tools";

Add-WindowsFeature "Web-Mgmt-Service";

Add-WindowsFeature "NET-Framework-45-Core";

Add-WindowsFeature "NET-Framework-45-ASPNET";

Add-WindowsFeature "NET-WCF-HTTP-Activation45";

Add-WindowsFeature "RSAT";

Add-WindowsFeature "RSAT-Role-Tools";

Add-WindowsFeature "RSAT-AD-Tools";

Add-WindowsFeature "RSAT-AD-PowerShell";

Add-WindowsFeature "SNMP-Service";

Add-WindowsFeature "SNMP-WMI-Provider";

Add-WindowsFeature "Telnet-Client";

Add-WindowsFeature "PowerShellRoot";

Add-WindowsFeature "PowerShell";

Add-WindowsFeature "WAS";

Add-WindowsFeature "WAS-Process-Model";

Add-WindowsFeature "WAS-Config-APIs";

Add-WindowsFeature "WoW64-Support";

 

5.2   Create permissions.ps1 with the below:

$sharepath = "C:\inetpub\wwwroot\"

$Acl = Get-ACL $SharePath

$AccessRule= New-Object System.Security.AccessControl.FileSystemAccessRule("everyone","full","ContainerInherit,Objectinherit","none","Allow")

$Acl.AddAccessRule($AccessRule)

Set-Acl $SharePath $Acl

The script sets the permissions over the site files to Everyone. Update this to match the site security requirements. It is best to have read/write/modify permissions only over the App_Data folder.

Note: The order of the commands in the DockerFile is important because they are executed from top to bottom. Make sure to update the file paths in the DockerFile to match the file path to those files on your computer:

RUN c:\permissions.ps1

RUN c:\iis_setup.1.ps1

6.       After the DockerFile is configured correctly, build the image with the Docker image build command:

Note: When using Windows 10 (Client OS) the memory limit depends on the isolation in which the container is ran and by default is 1 GB. For example, if you run the Docker container in Hyper-V VM the isolation level will be Hyper-V and the container will use the memory allocated to Hyper-V. The default 1 GB of memory for the container is not sufficient to run the Windows 10 OS and Sitefinity.

In this setup we are running on Client OS so we need to allocate the memory for the container when building it. For the purpose use the "-m <memory amount>" parameter in the build command.

Navigate to the directory where the DockerFile is located and type the following command

docker build -t sfImage -m 3GB .

·         -t is followed by the name of the image that will be built – in this case – sfImage

·         keep in mind that the command ends with a with a space followed by a dot ‘.’ – the dot signifies that we will use the DockerFile in the current directory

The command will use the microsoft/aspnet:4.7.1-windowsservercore-ltsc2016 that we defined in the DockerFile as a base and modify it according to the instructions we set in the DockerFile. After all the modifications have completed a new image will be created which will contain only the changes made to the original – the addition of Sitefinity web app files in the root IIS site and the modified system roles and services. This means our image will have a very small disk space footprint. We can create hundreds of similar images and all of them will share the same base. This way you could have images for numerous variations of Sitefinity setups without wasting disk space – Sitefinity for NLB, single hosted instance, hardened security, running in the latest .NET Framework and ASP.NET instance, etc.

7.       After the build completes, run the container with the command specifying the memory limit:

docker run -d -p 8000:80 -m 3GB --name sfImage sfContainer1

·         -m 3GB is the allocated ram for running this container

The command spins up a running container from sfImage which will be called sfContainer1. We could spin up hundreds of such running containers and they will only store the changes from the image that was used to start them. They will also be completely isolated from one another. In addition, starting and stopping containers from such images is a lot faster than provisioning an entire virtual machine.

8.       Get the IP of the container using command:

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" sfContainer1

This command outputs the IP address of the container. We need to get the IP address through a command. This is due to current limitations (as of this writing) for Windows containers in Docker. The command takes the network settings of the container.

9.       Request the container with the IP from the previous step and the site will startup. In this post it is assumed that the Sitefinity instance will be a new one and we are going to go through the startup wizard.

For the database server, use any supported database server accessible over your network.

IMPORTANT NOTICE: If you have Symantec Endpoint Protection Antivirus installed it will block the network requests to the container and you won`t be able to access it via the IP address. Even though on their site it is stated that there are no known issues with Windows containers, you should disable its firewall. If your organization is managing the antivirus you will need to call the admin to fully stop the firewall service or add an exception – if you turn it off it will say it is turned off, but it actually will not be. We used a virtual machine for testing with nested virtualization enabled as Windows containers require some virtualization for the network connectivity and file system isolation of the containers from the host OS.

Advantages of the Container Approach

It might seem unnecessary to containerize a monolithic application, but there are benefits:

-          Consistent runtime platform on all environments and on all dev machines – for example it would help avoid missing breaking changes introduced via updates on live that have not been deployed on dev or on other stakeholder environments

-          Isolating the app process from the rest of the OS, leading to better security

-          Allows the application to be easily deployed and run in a microservice architecture, which is the first step to refactoring portions of the large monolith and extract them to microservices

-          Saves a lot of HDD/CPU/RAM on the hosting server, because the OS is shared and no system resources are wasted

-          Fast provisioning of new instances

As with every new technology/approach there will be an initial learning curve and setup time, but that is a one-time event and after this you can enjoy the above benefits.

What’s Next

Give it a try and let us know how it went for you. Create an image that contains all the necessary build tools for consistent code compilation across all dev machines and CI environments, so you can streamline the process in your companies.

Are you interested? Let's get started!

Schedule a Demo    Start a trial

10 comments

Leave a comment
  1. KatyCiara May 05, 2018
    Thesis writing will be not An not difficult assignment. You if think legitimately regarding help with dissertation dissertation in front of start writing. Clear written goals. You should clear of your goals of writing.
  2. roise May 16, 2018
    Great post! I didn’t know about several of these resources and I’m going to go check them out now!<a href="http://howtomakeslimes.com" >how to make slime</a> 
  3. roise May 16, 2018
    Great post! I didn’t know about several of these resources and I’m going to go check them out now!  

    How to make slime

  4. adv May 21, 2018
    Play FreeCell Solitaire online for free. Simple gameplay, excellent graphics and unlimited undos Just visit Free freecell game of this website and play your favourite card game here Play freecell game online for free of cost and online.I like to play my desire card game here with my friends by inviting them.Thank you so much to this amazing card game Junction.
  5. Paul Jun 12, 2018
    I've raised a ticket with Sitefinity support and they've confirmed that they don't provide any support for containerized instances, so this is a bit of an academic article.  The last line "so you can streamline the process in your companies" is only valid if you're willing to do it without any support from Progress; it would be nice to see containerized instances supported and it'd be good to make it clear in the article that it's not supported if you want to look at it for your own production instances.
  6. Matthew Lewis Jun 25, 2018
    I was going through your blog and reading this. I thought I would leave my first comment. I really enjoyed reading this, love very words of it. Academic Writing Help Online
  7. John Bill Jul 03, 2018

    Few bloggers show the true side of the story and you are definitely among one of them. I have read your entire blog and there was not a single moment where I had taken an interval. It was that interesting.

    <a href="https://www.fashionbirdz.com">Fashion Blog | Fashion Birdz</a>

  8. bruno Jul 09, 2018
    Get free animal jam codes from here within minute.
  9. Zoya120 Jul 12, 2018
    I am happy to be here and this wonderful article. I have found here lots of interesting information for my knowledge I need. all the details you provide to us, it was very helpful and useful, thanks for sharing this amazing post.
    Toshiba Support Number
  10. internet marketing company Jul 20, 2018
    With a strong SEO strategy, your company website will become associated with the keywords used to find your services.  internet marketing company

    Leave a comment