Creating Containers
The concepts of containers and OS-level virtualization have their roots in the chroot system call in Unix V7 operating systems (OSes), which date back to the late 1970s. Starting with a simple concept of process isolation and chroot jails, where the process is running in an apparently isolated root directory, containerization has undergone rapid evolution and became a mainstream technology in the 2010s with the advent of Linux Containers (LXC) and Docker. In 2014, Microsoft announced support for Docker Engine in the incoming release of Windows Server 2016. This is where the story of Windows containers and Kubernetes on Windows begins.
In this chapter, we will provide you with a better understanding of containers for the Windows OS by highlighting important differences between containerization on Linux and Windows and container runtime types on Windows, namely...
Technical requirements
The requirements for this chapter are as follows:
- Intel Virtualization Technology (Intel VT) or AMD Virtualization (AMD-V) technology features enabled in the BIOS
- A minimum of 4 GB of RAM
- Windows 10 Pro, Enterprise, or Education (version 1903 or later, 64-bit) installed
- Visual Studio Code
For more information regarding the hardware requirements for running Docker and containers on Windows, please refer to https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/system-requirements.
Windows 10 versions starting with Anniversary Update (version 1607, build 14393) are supported, but version 1903 is recommended for the best experience since it comes with all the necessary features. For more details regarding Windows 10 versions and container runtimes compatibility, please refer to https://docs.microsoft.com/en-us/virtualization/windowscontainers...
Linux versus Windows containers
Containerization on both Linux and Windows aims to achieve the same goal – creating predictable and lightweight environments that are isolated from other applications. For Linux, a classic example of container usage can be running a Python RESTful API written in Flask, without worrying about conflicts between Python modules that are required by other applications. Similarly, for Windows, the containers can be used to host an Internet Information Services (IIS) web server that's entirely isolated from other workloads running on the same machine.
Compared to traditional hardware virtualization, containerization comes at the cost of being tightly coupled with the host OS since it uses the same kernel to provide multiple isolated user spaces. This means that running Windows containers on the Linux OS or running Linux containers on the Windows...
Understanding Windows container variants
Windows containers come in two distinct levels of isolation: process and Hyper-V. Process isolation is also known as Windows Server Containers (WSC). Initially, process isolation was available on the Windows Server OS only, whereas on desktop versions of the Windows OS, you could run containers using Hyper-V isolation. Starting with Windows 10, version 1809 (October 2018 Update) and Docker Engine 18.09.1, process isolation is also available on Windows 10.
Now, let's take a look at how these isolation levels differ, what the use cases for them are, and how to create containers by specifying the desired isolation type.
Installing Docker Desktop for Windows tooling
Creating applications for Kubernetes on Windows requires an environment for developing and testing Docker containers. In this section, you will learn how to install Docker Desktop for Windows, which is the recommended tooling environment for development, building, shipping, and running Linux and Windows containers on Windows 10. First, let's recap on the prerequisites and Docker's minimum requirements before continuing with the installation process:
- A minimum of 4 GB of RAM.
- The Intel Virtualization Technology (Intel VT) or AMD Virtualization (AMD-V) technology features enabled in the BIOS. Note that if you are using a VM as your development machine, Docker Desktop for Windows does not guarantee support for nested virtualization. If you want to find out more about this scenario, please refer to https://docs.docker.com/docker...
Building your first container
In the previous section, you have learned how to install Docker Desktop for Windows and how to run simple Windows and Linux containers. This section will demonstrate how to build a custom Docker image using Dockerfile and how to perform the most common actions on running containers, such as accessing logs and perform exec into a container.
As an example, we will prepare a Dockerfile that creates a Windows container image of Microsoft IIS hosting a demonstration...
Summary
In this chapter, you learned about the key aspects of the Windows containers architecture and the differences between the isolation modes provided by the Windows container runtime. We also covered how to install Docker Desktop for Windows and demonstrated how to perform the most important operations using the Docker CLI on the Windows platform.
This and the next two chapters will be the foundations of what you are going to learn about regarding Kubernetes on Windows in the rest of this book. In the next chapter, we will focus on managing state in Windows containers, that is, how to persist data when running containers.
Questions
- What are the kernel features that Windows exposes in order to enable containerization?
- What are the key differences between containerization on Linux and on Windows?
- What is the difference between Hyper-V isolation and process isolation? When should you use Hyper-V isolation?
- How can we enable LCOW on Windows 10?
- What command can we use to access logs for the main process in a Docker container?
- How can we start a new Powershell process inside a running container?
You can find the answers to these questions in the Assessments section of this book.
Further reading
This chapter has provided a recap of Docker containers on Windows. For more information concerning Windows containers, please refer to two excellent Packt books:
- Docker on Windows: From 101 to production with Docker on Windows, at https://www.packtpub.com/virtualization-and-cloud/docker-windows-second-edition.
- Learning Windows Server Containers, at https://www.packtpub.com/virtualization-and-cloud/learning-windows-server-containers.
- You can also check out the official Microsoft documentation on Windows containers, at https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/.