So you love Docker and you’ve heard that Windows Server 2016 will support Docker containers but you’ve no clue where to start? Worry no more as I swiftly take you through the basics of building your first Windows based Docker container image containing IIS and create a new container using our container image to host a basic static HTML website.
For this guide, I’ll be using a VM (virtual machine) running Windows Server 2016 which has been deployed using Microsoft’s Azure cloud. You might want to run a VM locally but if not, head over to Azure’s guide on deploying a Windows Server VM to Azure, simply replace all references in the guide for “Windows Server 2012 R2 Datacenter” with “Windows Server 2016 Technical Preview 4”.
(1) Install Windows Server 2016 and log onto the server (See link above for deploying a Windows Server 2016 VM to Azure)
(2) Open an elevated PowerShell prompt
(3) Run the following commands which will download and run Microsoft’s configuration script that will setup the Docker client, but more important configure the server as a container host.
(4) After about a minute or two the server will reboot as part of the configuration stage. Simply log back in and your see a PowerShell window open and continue executing the script we started in the previous step.
(5) During this next stage the script will enable container networking, create NAT rules, etc and then start installing the container OS image which will be downloaded from http://aka.ms/ContainerOSImage automatically.
Note - the final step may take some time depending on your internet connection speed and VM resources. My Azure demo VM which is a Standard A1 (1 core, 1.75 GB memory) machine took around an hour and a half to complete this step.
Before we dive into getting your first Windows based container up and running, I want to point out this technology is still in technical preview, so it may be rough around the edges and/or in some cases missing functionality.
With that out the way, I also wanted to mention one difference that you’ll notice if you’ve ever run Docker on Windows before, in that the “docker-machine” command is no longer available. This is because Windows Server 2016’s Docker implementation only supports Windows based containers due how the Docker isolation architecture works. Maybe in the future we might see the “docker-machine” command return so that we can run a Linux VM on Windows in-which to host our Linux based containers as well, but let’s not hold our breath just yet.
Let’s quickly confirm that Docker has been set-up by checking the Docker version of the client and server components. This is done by running the “docker version” command from a PowerShell command prompt which should return similar output to the image below.
Now that we’ve confirmed Docker has successfully installed, let’s go ahead and create a new image with IIS installed. We’ll also then move on to creating a new container using our new image which we’ll use to host our website that will be mounted from the hosts filesystem.
You’ll now be returned to the PowerShell prompt on the Windows Server 2016 host where we will now turn the container into our own base image with IIS installed.
Now that we have our custom container image, let’s finally wrap up this quick start guide by creating a container using our custom image and mounting an example website’s directory as a subdirectory under the IIS’s default website directory. For this demo, I’ve copied one of my static HTML websites to “C:\docker-data\website” on my Windows Server 2016 host. Alternatively rather than mounting a directory from the host to the container, I could have instead copied the files from the host to the container using the “docker cp” command.
If all went well, you should now be looking at your webpage called index.html hosted using IIS from the Docker container we created. Hopefully I will get around to producing more Docker documentation soon :-) In the meantime let me know if you hit any issues with the guide.
You may also be interested in my later post on Publishing Applications To Windows Containers Using Visual Studio Docker Tools (Whirlwind Tour).