Learning Windows Server Containers
上QQ阅读APP看书,第一时间看更新

Preparing a Windows Containers image

A Windows Containers image can be developed primarily in two ways: using PowerShell commands or by using Docker CLI commands. Every Windows Server Container or Hyper-V Container should be created from a base OS image. Windows Server 2016 TP5 comes with two types of base OS images, windowsservercore and nanoserver. The Windows Server we created on Azure comes with windowsservercore installed by default. You can install the nanoserver image by running the following command:

    docker pull microsoft/nanoserver

In this chapter, we will use Docker commands to create a Windows Containers image from scratch, which will host default index pages on the IIS web server. First let's check for base OS images installed on our containers host:

    docker images

The preceding command will give the following output:

windowsservercore is the base OS image used in the Windows Containers world and it forms the bottom-most layer of a container. As you can see, the image is still heavy on size with 7.75 GB. This additional size hurdle is overcome by a special type of server image called nanoserver images. For now, we will only use windowsservercore.

If you do not find any image on your container host, you can pull the image from Docker Hub by running the following command:

    docker pull microsoft/windowsservercore

If you want to search the repository, use docker search to get a list of all container images available.

You can list the number of containers running, exited, or paused on any host by using the following command:

    docker ps

The preceding command will give the following output:

As you can see, running docker ps lists the containers and the corresponding image names, status, and so on. The following list explains two methods that can be used to create windows server images:

  • Since containers are layered systems, we can start with creating a new container using the base OS image, start customizing the container as per your needs using PowerShell or Windows CLI, and once you are done convert it into an image. Though this sounds simple, this is not quite often how we develop containers. Since we do not maintain a list of steps executed before creating an image, this method is more error prone and not recommended for production scenarios.
  • The second and the most preferred way is to write the instructions to prepare an image in a special type of file called Dockerfile. Dockerfile is a set of instructions that follow Docker semantics and they are compiled by Docker Engine while preparing the image. Since we are documenting our configuration as code, it can be easily incorporated in continuous integration or deployment practices.