Getting Started With Containers (Part 4)

If you would like to read the other parts in this article series please go to:

In my previous article, I showed you how to set up Windows Server 2016 as a container host, and how to deploy a base OS image. Now that we have one or more base images in place, it is time to move forward with building some containers.

Before we create anything else, I want to take just a moment and show you a couple of PowerShell cmdlets that you can use to make sure that the necessary components are in place. The commands that I recommend running are:

Get-ContainerHost

Get-VMSwitch

Get-ContainerImage

These cmdlets should confirm the existence of the container host, virtual machine switch, and container images that you put into place in the previous article. You can see an example of the output from these commands in the Figure A.

Image
Figure A: It’s a good idea to make sure that the required components are in place.

Now that the container host and the base images are in place, the next thing that we have to do is to install Docker. In order to do this, you will have to use a PowerShell cmdlet called Invoke-WebRequest. The Invoke-WebRequest cmdlet is a PowerShell tool for downloading a file from the Internet. This cmdlet requires two parameters. First, you will need to specify the URL of the resource that you are going to be downloading. Second, you must specify the path and filename that you want to use for storing the resource on your local system.

In case you are wondering why this step is necessary, it is because Microsoft has created a PowerShell script called Update-ContainerHost.ps1. This script is used to install Docker onto a container host, but the script is not included with Windows Server by default. Therefore, you are going to have to use the Invoke-WebRequest cmdlet to download the script.

In my case, I am creating a folder on my Windows Server named C:\Scripts, and using that folder as the download target. These are the commands that I used:

C:

CD\

MD Scripts

CD Scripts

Invoke-WebRequest https://aka.ms/tp5/Update-Container-Host -Outfile Update-ContainerHost.ps1

You can see what these steps look like in Figure B.

Image
Figure B: I downloaded the Update-ContainerHost.ps1 script to C:\Scripts.

The next step in the process is to use the script to install Docker. This is a simple process. As you can see in Figure C, I used the DIR command to make sure that the script had been properly downloaded. I then executed the script to launch the installation process.

Image
Figure C: The Update-ContainerHost.PS1 script installs Docker.

Once Docker has been installed, you can begin building containers. For those who have never worked with Docker before, the most important thing to remember is that Docker is hierarchical. Docker containers stem from a base image, but often times a container will be based on another container. Let’s use IIS as an example. Suppose for a moment that you had a particular Web application that you wanted to containerize. A Web application can have a lot of moving parts. For example, there is a server operating system, there are the Web server components, there is the Web application code, and depending on the Web application there might also be databases and other components. My point is that containers are usually small, simple, and modular. There is nothing simple about the imaginary Web application that I just described. This is where a hierarchy of containers comes into play.

As I explained early on in the series, one of the things that containers are really good for is eliminating redundant code. Suppose for a moment that you needed to host ten different Web applications, and that for whatever reason, each application needed its own Web server. Now suppose that you decided to host these Web applications as virtual machines. In addition to the Web application code, you would have ten presumably identical copies of the Windows Server operating system and ten identical copies of IIS. All of this redundancy wastes a lot of system resources.

The base OS image allows you to eliminate operating system redundancy. If the imaginary situation that I just described were to be based around the use of containers, then the containers could very easily eliminate most of the operating system level redundancy.

In spite of this however, there would still be ten redundant copies of IIS that are being used to host the Web applications. What if IIS could also be containerized? By containerizing IIS, you could get away with having a single instance of IIS. Each of the Web applications could also be containerized.

Right now you might be thinking, OK, that’s great, but it sounds like a lot of work to set things up in this way. Actually, it is fairly easy to set up a hierarchical IIS deployment. Remember that Docker already has a base OS image. As such the first thing that you would probably want to do is to create a dedicated base image that could be used specifically for IIS.

So why would you do this? There are actually several advantages to creating an IIS specific base image, but the biggest advantage is consistency. By creating a dedicated IIS base image, you can make sure that all of your containerized Web applications run on a similar platform. The underlying Web servers would all be running identical configurations and an identical set of patches.

So how would you create an IIS base image? It is actually surprisingly easy to do. There are two things that you are going to need. First, you will need the name of the base image that you plan on using. If you look back at Figure A, you can see that I have a base image called WindowsServerCore, so that’s the image that I will use in this example. The other thing that you are going to need is a name for the base container that you are creating. The example that Microsoft provides is a container named IISBase. The command for creating such a container is:

Docker Run –Name IISBase –it WindowsServerCore cmd

This command creates the container and opens a shell session within the container. From there, you can install IIS by entering these two commands:

PowerShell.exe Install-WindowsFeature Web-Server

Exit

The last thing that you will have to do is to commit the newly created IIS base image container by using the Docker Commit command. The actual command that you will use is:

Docker Commit IISBase WindowsServerCoreIIS

This command creates a container image that uses the name Windows Server Core IIS.

Conclusion

Hopefully, the explanation that I have provided makes sense, but don’t worry too much if it doesn’t. My plan is to come back in Part 5 and walk you through the container creation process. I also want to take a step back and talk about some of the things that can go wrong with the Docker deployment process.

If you would like to read the other parts in this article series please go to:

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top