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

Pulling images from Docker Hub

In this section, we will use an existing Docker image to create a new container. Docker Hub is a public repository for storing Docker images. Docker images can be made up of Linux base OS or windowsservercore OS. Since OS kernels are completely different, containers made up of Linux cannot be installed on Windows and vice versa. At this point we cannot differentiate by looking at the name if the base OS is made up of Linux/Windows.
If you try to install or pull a Linux image on Windows, it might fail with an error as follows:

Microsoft has also published a few docker images starting with microsoft/ that are made up of both Linux and windowsservercore base. Follow these steps to search and create a new container using a windowsservercore-based image called microsoft/iis:

  1. Run the following command to search images starting with microsoft:
       docker search microsoft

This will list containers containing the word microsoft, as shown in the following screenshot:

  1. Now let's try pulling an image called microsoft/iis, which is a Windows Server Core image with windowsservercose as base OS image and it comes installed with IIS web server. Run the following command to pull the image on to the container host:
       docker pull microsoft/iis

The docker pull command is used to download the images from remote repositories. By default, Docker will search for images on Docker Hub. Once downloaded, Docker maintains a local cache of images:

  1. Now if you list the local images by typing docker images, you should see the microsoft/iis image alongside the other base OS images, as shown in the following screenshot:
  1. Now let's create a new container using the above image. Run the following command to create a new container using microsoft/iis:
       docker run -t -d -p 80:80 microsoft/iis cmd

docker run can be used to create a new container using an image that is locally available. Docker tries to download the image from the public repository if it is not found locally. The following are the parameters of the preceding command:

  • -t: This switch is used to let Docker enable a pseudo terminal for this container.
  • -d: This switch lets Docker know to run the container in detached mode. By design, Docker containers running in detached mode exit as soon as the parent process used to create the container exits.
  • -p: This switch is used to configure port mapping from the container host to the new container.
  1. Now if you try to reach port 80 of the container host, you should be able to see the default home page of the IIS, as shown in the following screenshot:
  1. You can also check the container running by calling the following command:
       docker ps -a

This shows the running containers:

Hurray! We have successfully created a new container. The new container is running on port 80 (PORTS section) and it is named randomly as elegant_kowalevski by Docker Engine. Docker assigns a unique ID, c8ee2696da3b, for every container; both the ID and names can be used to interact with a running container. We will see more about managing containers in our next chapter.