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:
(For more resources related to this topic, see here.)
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:
Important: Windows 10 only supports Hyper-V Containers created using NanoServer Base OS Image; it does not support Windows Server Containers.
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.
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:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Restart-Computer –Force
Set-ItemProperty -Path 'HKLM:SOFTWAREMicrosoftWindows NTCurrentVersionVirtualizationContainers' -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:TEMPdocker-1.13.0-dev.zip" –UseBasicParsing
Expand-Archive -Path "$env:TEMPdocker-1.13.0-dev.zip" -DestinationPath $env:ProgramFiles
$env:path += ";c:program filesdocker"
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:Program FilesDocker", [EnvironmentVariableTarget]::Machine)
dockerd --register-service
Start the Docker Service by running the following command:
Start-Service docker
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:
docker images
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-technical-preview, 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.
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/).
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.
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:
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.
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
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 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.
Further resources on this subject:
At Packt, we are always on the lookout for innovative startups that are not only…
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…