In this blog we will setup Sitecore 8 on a Windows Server 2016 Docker container, some basic understanding of Sitecore, Windows server and Docker is required and will be of certain advantage, but if you do not know much about them it’s ok, you are here to learn. so let’s dive in and get started.
- Identify the images and download from Docker HUB.
We need to pull/download the images from Docker hub/registry to begin, an image is an inert, immutable, file that’s essentially a snapshot of a container. Images are created with the build command, and they’ll produce a container when started with run.
I have identified following two images for our Sitecore on Docker.
If you are aren’t sure about which image you are looking for then either from command line you can go and search for the image, however https://hub.docker.com/explore/ is the best place to start with.
Since I already know the name of the image, I’ll go and pull it from registry.
Registry: A service responsible for hosting and distributing images. The default registry is the Docker Hub. Repository. A collection of related images (usually providing different versions of the same application or service)
If you would like to search on Docker command line, then you can use the following command and it should provide you with Microsoft images listed on Docker hub.
#docker search Microsoft
We will select Microsoft/IIS and proceed to pull the image from Docker registry.
- Pull/Download image from Docker Hub/Registry.
To build the container we will have to download the image or multiple images in our case, because we will have one IIS web server and a backend SQL server.
For Docker images certain mannerism is followed, so I suggest you visit http://docs.docker.com
Let’s back to downloading image from Docker.
- Download IIS Webserver
Note: I had already downloaded that image previously hence it says already exists.
- Download Microsoft/mssql-server-windows-express
If you are downloading it for first time, here’s what you’ll see on your screen. The time it takes to download it completely dependent on your bandwidth, if you are running your host machine on any cloud platform then it shouldn’t be a problem in downloading and should not take more than few mins.
Here’s the confirmation on images download.
So you can see that we have two images being pulled from Docker Hub a. microsoft/mssql-server-windows-express b. microsoft/iis
We will first work with microsoft/iis, make some required changes and then deploy Sitecore.
Let’s build the container from the image and get going.
- Build Container from image (IIS Server)
I’ll show you how to build the container from image shortly, however for better understanding of Docker I’d encourage you spend sometime with Docker help before you go ahead.
#Docker –help (two dashes)
Back to building container.
We will be using following command in Docker to build the container from image.
# docker run –rm –d –p 81:80 microsoft/iis
Run: tells Docker to run a command in new Docker container, so it creates a new container to execute all of the following commands on:
–rm: automatically removes the container after existing it and this is actually very important, otherwise it gets cached (Docker keeps it), it will lock up the name and consequently, you’re filling up the hard drive partition of your host
-d: run container in background and print container ID for information.
-p port:port: bind host port 81 to container port 80 so that we can access container outside container/host as well.
For example: if your host machine is having live IP 220.127.116.11 and you associate your host port 81 to container port 80, then using the following url you can access the site from anywhere on internet.
If your command ran successfully then you should be able to see output something similar to above screenshot, the long alpha numeric character are the container ID. You might need part of it in future use.
Secondly, you can also try to access the site outside your host machine if you wish to using the method explained above (http://18.104.22.168:81). Make sure you have allowed port 81 in your host machine firewall, otherwise it won’t work.
Alright, let’s get back to working with our new container, let’s get couple of windows feature enabled.
- Enable Windows Feature for ASP.net
So far we have only downloaded and build our container from image, now we have to go and enable some of the windows feature so as to work with IIS/Asp.net
So as to enable some of the windows feature within Container we will be using PowerShell, here’s the Docker command to get PowerShell extension on container.
Just before that make a note of your container ID, because using the container ID you will be able to run the PowerShell.
Now we will run the Docker command to get Powershell prompt for given container.
# docker exec –it 37a6 PowerShell
Before you start enabling windows feature it’s a good practice to see what’s already enabled and what needs to be, I like doing that, so that I can be sure that my commands are working fine and as per expectation.
Make a note of second column with heading as “Name”, there are two feature down the list (not visible in screenshot) which we will have to enable.
With PowerShell it’s quite easy to do so and here’s how it’s done.
Once started here’s what you will see as your first screen and the last screen shot shows you the confirmation.
Collecting data info.
Let’s quickly enable the other feature as well.
In our case it’s already enabled so here’s what we get.
- Build Container from image (SQL Server)
So let’s quickly go and run the SQL Container in background, since we have already downloaded the image it should be pretty quick and easy, as we already know how to run the container from image.
# docker run –rm –d –p 1433:1433 –e sa_password=P@ssw0rd1234 –e ACCEPT_EULA=Y microsoft/mssql-server-windows-express
Few changes in this Docker command.
- We are exporting port 1433 of SQL Server for both host and container
- We are specifying sa password for sql
- We are accepting SQL end user license agreement, this is important without which SQL won’t start.
Here’s the interesting part:
To restore the Sitecore databases I do not use the command line, it’s much easier to connect your Sql Server Management Studio to container and easily restore the DB’s.
- Connecting SSMS to SQL Container
There are couple of ways you can restore your Sitecore DB’s to SQL container however for the learning purpose or maybe in production too, I find it easier to use SQL Server Management Studio connected to container or host machine.
There are two scenarios that I’ll show you to connect your SQL server management studio to either your container or your host machine.
- Your host machine is already having SSMS installed and you need to connect to your container from host.
- In this case find out the IP address of your container
- Ping back and forth between host machine and container
- If they are able to talk to each other than point your SSMS to container IP and use SA user/password details to login.
- To test connectivity login to container PowerShell and ping.
- Server name: IP address of your SQL container, you can find out couple of ways
- Connect to your SQL Server using Powershell (Refer to section 4) and run following command and it should let you know the local IP address of your container
- Other method to find out the IP address is using following command
# docker inspect containerID
This command will show you the local IP address of container at the end of the output.
- If you are like me and would like to test SQL connectivity from different perspective then you can connect from your host machine IP address.
You can run your SSMS outside your host and point it to your live IP, make sure your firewall is allowing it go through, not a very secure way, nonetheless you can define security methods once you are logged in.
For the purpose of this demonstration, connecting to your Container from host machine is good enough.
Now as such you are connected let’s quickly attach your DB’s so that we are done with our SQL part and can move back to Sitecore setup in IIS Container.
Note: through SSMS server you are connecting to your SQL container which means using SSMS GUI when you try to restore the DB the SSMS will try to restore from SQL Container, it will look for those DBS MDF/LDF there in container, so make you copy db on to that SQL Server.
How to copy the DBs to SQL container ?
Let’s look at step 7 quickly.
- Copying DBs to SQL Container
You have to using Docker command to copy DBs from your local host machine to SQL Container so as to attach/restore those DBs.
#docker cp Databases grave_perlman:/c:\
Let’s understand this.
cp: simple copy parameter to pass on
Database: Name of the local folder on host machine which contains all the DBs.
grave:Perlman:/c:\ à grave:Perlman is the name of the container and later part is the path location where you want to copy your database folder.
Now you can go ahead use SSMS and restore the DBs, I am not going to show that part here. Once you have restore the DBs then you can move to step 8:
- Cleanup IIS Container.
Before you start copying the Sitecore application, I like getting rid of any default IIS setting/website.
So I’ll quickly run
# remove-website –Name “Default web site”
- Deploying Sitecore App to IIS Container.
Alright, so the Sitecore App fun begins here. Let’s copy the application folder to IIS container, create new website and define the permissions in coming few steps. There are other config changes that we will have to make to get the Sitecore up and running.
Let’s go step by step.
- Copy Sitecore app folder to inetpub path, not that you have to use this but that’s the default path.
Alright, so let’s understand what’s happening here:
- My current location is c:\docker\sitecore 8.2\wwwroot
- I am trying to copy everything wwwroot in current location to IIS container under c:\inetpub\wwwroot\
- Hence the command #docker cp . jolly_stallman:/c:\inetpub\wwwroot\ will copy everything from my current location to remote location in IIS container.
Now let’s deploy new website in IIS using PowerShell
#New-Website –Name “Sitecore” –Port 80 –PhyscialPath “C:\inetput\wwwroot” –ApplicationPool “.Net v4.5”
Great, so our application is deployed and if you have done your license file and network path setting correctly in Sitecore.config and Connectionstring.config then you should be able to see Sitecore default page.
#docker run –d –p 81:80 microsoft/iis
- There’s all possibility that you might be able to see the default page, might also be able to login to admin but when you try to open the control panel, you’ll come across this error.
In such situation we have to go and check the permission of folder where we have copied our Sitecore application.
So let’s first check, then set the policy and recheck the page for final confirmation.
- Go to location where you have deployed your application and run following command
- Set the permission for Network Service as follows and hopefully it should work for you, if doesn’t then it’s definitely to do with permission only.
$acl = Get-Acl c:\inetpub
$permission = “NETWORK SERVICE”,”FullControl”,”Allow”
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl | Set-Acl c:\inetpub