On Windows platforms, you can run containers in two modes: process isolation and Hyper-V isolation. In process isolation mode, containers share the OS kernel with the host and hence are lightweight and similar to how containers work on Linux systems.
When we install Docker on a Windows server, the default mode of operation is process isolation. And enabling Hyper-V is optional. However, if we need to run Linux containers, enabling Hyper-V is required.
Windows containers need to have the same build version as the version of the container host OS they run on. Container images tagged as 1809 would work on the latest 1809 Windows version builds. However, if you have built container images on a lower version of Windows than the container host OS, you can run these containers with Hyper-V isolation, which requires enabling Hyper-V.
Prerequisites
If the container host is running on bare-metal, you need to enable the hardware virtualization feature, such as Intel VT-x, in BIOS. And if the container host is running from Hyper-V or from a cloud environment, you need to enable nested virtualization in the base platform.
Installing the Hyper-V feature (Optional)
You can install Hyper-V on Windows Server using the PowerShell command below:
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
You can switch between process isolation and Hyper-V isolation during runtime using the parameter isolation while spinning up Docker containers.
Installing the containers feature
You need to install container feature on the Windows container host. Use the command below to install the containers feature and reboot the host.
Install-WindowsFeature containers -Restart
Installing Docker
Docker consists of two major components: the Docker engine and the Docker client. The Docker engine is available in two editions: Docker Engine CE and Docker Engine EE. The Docker Engine CE is a free product. Conversely, the Docker Engine EE requires a license.
In this tutorial, we will install Docker Engine EE on Windows Server 2019. To get the full functionality of the EE edition, we need to purchase the EE license from Docker.
As a first step, install the Docker-Microsoft PackageManagement Provider module from the PowerShell Gallery.
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
We can use the commands below to view the installed package provider and the Docker package made available through it.
Get-PackageProvider -ListAvailableget-packagesource -ProviderName DockerMsftProvider
Next, we will use the Package Management PowerShell module command Install-Package to install the latest version of Docker.
Install-Package -Name docker -ProviderName DockerMsftProvider
Docker Verification
After installing the Docker package, we need to start the Docker service using the command below:
Start-Service Docker
When we run the Docker service for the first time, it creates a virtual switch/interface. You can verify the Docker virtual network creation using the Docker command below. The default name of the bridge or switch in a Windows environment is NAT.
docker network ls
This virtual switch lays the foundation of networking for containers to communicate with each other as well as talk with the container host.
Next, you can run the Docker version command to check the details of our deployment setup. you can verify the Docker engine and client version from the command output.
docker version
To confirm whether Docker client-engine communication is working fine and installation is complete, run the command docker info. This provides us with system metadata along with the current container stats.
Start Windows container on Windows Server 2019
Now that you have completed the installation and verified everything is working smoothly, it's time to run our first Windows container on Docker.
Here we need to consider two factors. First, we can create Windows container images with four container base images: Windows Server Core, Nano Server, Windows, and IoT Core.
When we spin a container from these images, we need to verify the compatibility between the container host OS and the container base image. In other words, containers based on Windows Server Core, Nano Server, or Windows as the base image can run on a Windows 2019 container host. However, a container based on an IoT Core image cannot run on Windows Server 2019. An IoT Core container requires Windows IoT Core as a container host.
Second, to repeat, Windows containers need to match the version of the container host OS. Container images with the 1809 tag work with the latest Windows versions. However, if we have container images built on a lower version of Windows than the container host OS, we can run these containers with Hyper-V isolation
Considering these two factors, let's verify the build version of our container host.
winver
As the container host build version is 1809, let's try to download a Nano Server image from the Microsoft image/container registry to the local machine.
docker image pull mcr.microsoft.com/windows/nanoserver:1809
We can verify the locally available image along with its metadata information, such as size, image ID, and creation date.
docker image ls
We can use the downloaded image for baking our application into it and creating a new container. But for simplicity, let's launch a basic container that will run just a simple command inside the OS and exit.
docker container run mcr.microsoft.com/windows/nanoserver:1809 hostname
This command created a new container from the Windows Nano Server image, and the container outputted the machine name of the container, a random ID set by Docker. To see more information about the container we created just now, run the command below.
docker container ls -a
Wrapping up
You have successfully installed a Windows container on Windows Server 2019.
No comments: