In this article by Srikant Machiraju, author of the book Learning Windows Server Containers, we will get acquainted with containers and containerization. Containerization helps you build software in layers, containers inspire distributed development, packaging, and publishing in the form of containers. Developers or IT administrators just have to choose a BaseOS Image, create customized layers as per their requirements, and distribute using Public or Private Repositories.Microsoft and Docker together have provided an amazing toolset that helps you build and deploy containers within no time. It is very easy to setup a dev/test environment as well. Microsoft Windows Server Operating System or Windows 10 Desktop OS comes with plug and play features for running Windows Server containers or Hyper-V Containers.Docker Hub,a public repository for images,serves as a huge catalogue of customized images built by community or docker enthusiasts. The images on DockerHub are freely available for anyone to download, customize,and distribute images.
In this article, we will learn how to create and configure container development environments. The following are a few more concepts that you will learn in this article:
- Preparing Windows Server Containers Environment
- Pulling images from Docker Hub
- Installing Base OS Images
(For more resources related to this topic, see here.)
Preparing Development Environment
In order to start creating Windows Containers,you need an instance of Windows Server 2016 or Windows 10 Enterprise/Professional Edition (with Anniversary Update). Irrespective of the environment, the PowerShell/Docker commands described in thisarticlefor creating and packaging containers/imagesare the same.The following are the options we have to setup a windows server container development environment:
- Windows 10: Using Windows 10 Enterprise or Professional Edition with Anniversary update you can create Hyper-V Containers by enabling the containers role. Docker or PowerShell can be used to manage the containers. We will learn how to configure the Windows 10 environment in the following section.
Important: Windows 10 only supports Hyper-V Containers created using NanoServer Base OS Image; it does not support Windows Server Containers.
- Windows Server 2016: There are two options for working with containers on Windows Server 2016:
- You can download the Windows Server 2016 ISO from here (https://www.microsoft.com/en-in/evalcenter/evaluate-windows-server-techn...) and install it on a virtual machine running on Hyper-V or Virtual Box.For running Windows Server 2016 the host machine should have Hyper-V virtualization enabled.Additionally, for the containers to access theInternet, ensure that thenetwork is sharable between the host and Hyper-VVMs.
- Windows Azure provides a readymade instance of Windows Server 2016 with Containers configured. This so far is the easiest option available.
In this article,I will be using Windows Server 2016 with Containers enabled on Azure to create and manageWindow Server Containers. Windows Server 2016 is still in preview and the latest version available at the time of writing is Technical Preview 5.
Containerson Windows 10
The following steps explain how to setup a dev/test environment on Windows 10 for learning container development using Hyper-V Containers. Before continuing further, ensure thatyou're running Windows 10 Professional/Enterprise version with anniversary update. For validating Windows Edition on Windows 10,click Start and type This PC, andthen right-click on This PC and click on Properties. Check the Windows Edition section for the Windows 10 edition. If your PC shows Windows 10 Enterprise or Professional, you can download and install the Anniversary update from here (https://support.microsoft.com/en-us/help/12387/windows-10-update-history).
If you do not have any of the above, please proceed to the following section, which explains how to work with containers using Windows Server 2016 environment on Azure and on-premises. Follow these steps to configure Hyper-V containers on Windows 10:
- Click on Start Menu and type powershell. Right-click powershell CLI (Command Line Interface) and Run as administrator.
- Run the following command to install the containers feature on Windows 10:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
- Run the following command to install the Hyper-V containers feature on Windows 10. We will only be using Windows Server Containers in this article:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
- Restart the PC by running the following command:
- Run the following command to update the registry settings:
Set-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Containers' -Name VSmbDisableOplocks -Type DWord -Value 1 -Force
Although PowerShell can be used to manage and run containers, Docker commands give a full wealth of options for container management. Microsoft PowerShell support for Windows Container development is still a work in progress, so we will mix and match PowerShell and Docker as per the scenarios.
Run the following set of steps one by one to install and configure Docker on Windows 10:
Invoke-WebRequest"https://master.dockerproject.org/windows/amd64/docker-1.13.0-dev.zip" -OutFile"$env:TEMP\docker-1.13.0-dev.zip" –UseBasicParsing Expand-Archive -Path "$env:TEMP\docker-1.13.0-dev.zip" -DestinationPath $env:ProgramFiles $env:path += ";c:\program files\docker" [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine) dockerd --register-service
Start the Docker Service by running the following command:
- In order to develop windows server containers, we need any Windows Base OS Image,such as windowsservercore or nanoserver. Since Windows 10 supports nanoservers only, run the following command to download thenanoservercorebase OS image. The following command might take some time depending on your bandwidth; it downloadsand extracts thenanoserver base OS image, which is 970 MB in size approximately:
docker pull microsoft/nanoserver
Important: At the time of writing, Windows 10 can only run Nano Server Images. Even though the windowsservercore image gets download successfully, running containers using this image will fail due to incompatibility with the OS.
Ensure that the images are successfully downloaded by running the following command:
Windows Server Containers On-Premise
This section will help you to download and install Windows Server 2016 on a Virtual Machine using a hosted virtualization software such as Hyper-V or Virtual Box. Windows Server 2016 comes with two installation options, Windows Server 2016 Core and Windows Server 2016 Full feature, as shown in the following screenshot:
Windows Server 2016 Core is a No GUI version of Windows with minimalistic server features and bare minimum size, whereas thefull version is the traditional Server Operating System and it comes with all features installed. No matter which installation option you choose, you will be able to install and run Windows Server Containers. You cannot change the NoGUI version to full version post installation, so make sure you are choosing the right option during installation.
You can download the Windows Server ISO from here (https://www.microsoft.com/en-in/evalcenter/evaluate-windows-server-techn..., make sure you copy the Activation Keyas well from here) and setup ahostedvirtualization software such as Virtual Box or Hyper-V. Once you start installing from the ISO you will be presented with the following screen, which lets you select full installation with Desktop experience or Just the core with Command Line Interface.
Windows Server Containers on Azure
On Azure we are going to use an image that comes preinstalled with the containers feature. You can also start with plain Windows Server 2016 on Azure and install the Windows Containers role from Add/Remove Windows Features and then install Docker Engine or use the steps mentioned in Containers on Windows 10.
In this article, we are going to create Windows Server 2016 Virtual Machine on Microsoft Azure. The name of the image on Windows Azure is Windows Server 2016 with Containers Tech Preview 5. Microsoft Azure does not support Hyper-V containers on Azure. However, you can deploy these container types when running WS 2016 on premises or on Windows 10.
Note:For creating a VMon Azure you would need an Azure account. Microsoft provides a free account for beginners to learn and practice Azure for 30 days/$200. More details regarding creating a free account can be found here (https://azure.microsoft.com/en-in/free/).
Container options on WS 2016 TP5
Windows Server 2016 supports two types of containers: Windows Server Containers and Hyper-V Containers. You can run any of these Containers on Windows Server 2016. But for running Hyper-V Containers we would need a container hostthat supports Hyper-V Nested virtualization enabled,which is not mandatory for Windows Server containers.
Create Windows Server 2016 TP5 on Azure
Azure VMs can be created using a variety of options such as Management Portal (https://manage.windowsazure.com), PowerShell,or Azure CLI. We will be using the new Azure Management Portal (codename Ibiza) for creating an Azure VM.
Please follow these steps to create a new Windows Server 2016 Containers Virtual Machine:
- Login to the Azure Management portal, https://portal.azure.com.
- Click on +New and select Virtual Machines.
- Click on See All to get a full list of Virtual Machines.
- Search using text Windows Server 2016 (with double quotes for full phrase search).
- You will find three main flavors of Windows Server 2016, as shown in the following screenshot:
- Click Windows Server 2016with Containers Technical Preview 5 and then click Create on the new blade.
- Select Resource Manager as thedeployment model.
- Fill in the parameters as follows:
- Basic settings:
- Name: The name of the Virtual Machine or the host name.
- VM Disk Type:SSD (Solid State Disk).
- User name: Administrator account username of the machine. This will be used while remotely connecting to the machine using RDP.
- Password: Administrator password.
- Confirm Password: Repeat administrator password.
- Subscription: Select the Azure Subscription to be used to create the machine.
- Resource Group: Resource group is a group name for logically grouping resources of a single project. You can use an existing resource group or create a new one.
- Location: The geographical location of the Azure Data Center. Choose the nearest available to you.
- Click Ok.
Select Size and click on DS3_V2. For this exercise,we will be using DS3_V2 Standard, which comes with four cores and 14 GB memory.
SelectDS3_V2 Standard and click Select:
Click on Settings. The Settings section will have most of the parameters pre-filled with defaults. You can leave the defaults unless you want to change anything and then click OK.
Check a quick summary of the selections made using the summary tab and click OK. Azure starts creating the VM. The progress will be shown on a new tile added to the dashboard screen,as shown in the following screenshot:
Azure might take a couple of minutes or more to create the Virtual Machine and configure extensions. You can check the status on the newly created dashboard tile.
Installing Base OS Images and Verifying Installation
The following steps will explain how to connect to an Azure VM and verify if the machine is ready for windows server container development:
Once the VM is created and running, the status of the VM on the tile will be shown as Running:
We can connect to Azure VMs primarily in two ways using RDP and Remote PowerShell. In this sample, we will be using RDP to connect to the Azure VM.
Select the tile and click on the Connect icon. This downloads a remote desktop client to your local machine, as shown in the following screenshot:
Note: If you are using any browser other than IE 10 or Edge,please check for the .rdp file in the respective downloads folder.
Double-click the.rdp file and click Connect to connect to the VM.
Enter the Username and Password used while creating the VM to login to the VM.
Ignore the Security Certificate Warning and click on Yes.
Ensure that the containers feature is installed by running the following command. This should show the Installed State of containers,as shown in the following screenshot:
Get-WindowsFeature -Name Containers
Ensure that thedocker client and engine is installed using the following commands on PowerShell CLI and verify the version:
Docker Info provides the current state of thedocker daemon,such as the Number of Containers running, paused or stopped, the number of images, and so on, as shown in the following screenshot:
In this article, we have learnt how to create and configure windows server container and Hyper-V environment on Windows 10 or Windows Server 2016. Windows 10 professional or Enterprise with Anniversary update can be used to run Hyper-V Containers only.
Resources for Article:
- Understanding Container Scenarios and Overview of Docker [article]
- HTML5: Generic Containers [article]
- OpenVZ Container Administration [article]