Chapter 8. Introducing Containers

In this chapter, we cover the following recipes:

  • Configuring a container host
  • Deploying a hello world sample
  • Deploying IIS in a container
  • Using a Dockerfile to create and use a container

Introduction

As a method of Unix virtualization, containers have been around for quite a while. To a large degree, containers serve as an approach for deploying applications popularized by the open source Docker initiative. With Windows 2019, Windows Server supports Docker and Docker containerization integrated with Hyper-V.

Most of the administration you are likely to do with containers in Windows Server 2019 is done not by cmdlets, but by a command-line tool called docker.exe. For those used to PowerShell's object-oriented and task-focused approach, you may find this application hard to use. I daresay you are not alone. The docker.exe application works in PowerShell and you can, of course, use PowerShell to wrap the command.

With containers in Windows Server 2019, you need to download and install a number of components. In the Deploying a hello world sample recipe, you download and make use of OS base images. These require an internet connection.

Containers provide scalability by enabling you to run multiple containers directly on top of Windows Server 2019. This takes up considerably fewer resources than if each container was contained in its own separate virtual machine (VM).

This approach has a theoretical security vulnerability whereby malware enables bad actors to access one container's contents from another. To reduce those risks, you can run containers inside Hyper-V. With Hyper-V containers, the container is run inside a completely virtualized environment that provides additional hardware-level security, albeit at the price of performance. Hyper-V containers are useful in a shared tenant environment, where one container host can run containers belonging to different organizations.

Once you have configured a container host, it's a great idea to test that you can run containers successfully. There are a number of sample containers you can download to test out the basic container functionality (and the use of docker.exe). You use these in the Deploying a hello world sample recipe, as well as look at using containers with Hyper-V virtualization.

With containers, you package applications inside a container, which then makes use of a shared kernel. The (single) shared kernel provides kernel-level features for all the containers deployed on a container host. The container then runs an application making use of the shared kernel.

To deploy containers in Windows Server 2019, you need to provide both a container host (to run the container) and one or more images, which Docker can run as a container. You can also download base operating system images from the Docker repository and build your own images on top.

You build and deploy containers using docker.exe (and in some cases, Hyper-V), as you see in this chapter. In the Deploying a hello world sample recipe, you will explore and download key base images.

An application you can easily containerize is IIS. This is pretty simple, as you can see in the Deploying IIS in a container recipe.

If you are deploying containers, you can use a Dockerfile, a simple text file with build instructions. Docker uses this file to build a customized container image, which you can then deploy. You look at creating and using an image using a Dockerfile in the snappily-named Using a Dockerfile to create and use a container recipe.

This chapter provides only an introduction to containers, images, docker.exe, and Dockerfile files. There is much more to explore with containers. Topics including Docker networking, Docker Swarm, and more are outside the scope of this book. To discover more about containers than we can fit here, look at Packt's book: Learning Windows Server Containers by Srikanth Machiraju. And, for more on the endearingly awful docker.exe application, take a look at Docker on Windows by Elton Stoneman.

For more information on Windows containers, see this link: https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/.

Note

The recipes in this chapter use the command-line tool docker.exe. For those familiar and comfortable with all of PowerShell's awesomeness, this is going to come as a bit of a shock. docker.exe has no tab completion, all output is minimal text blobs (no objects), parameter names seem random and curious, the online help is not very helpful, and the error reporting is downright atrocious. docker.exe is not all that easy to get to grips with, is less easy to automate than other Windows features, and feels very, very slow even on a well-equipped workstation. Containers as a feature are awesome—if you plan to adopt them, consider spending some time building a good framework and framework tools for your environment. Additionally, using major search engines to discover aspects of containers tends to yield a lot of useful pages, but focused on Linux as a container host and is used in a container.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.30.162