When I talk about setting up containers and you are getting ready to start using containers, there is one major requirement that we need to consider. The operating system on the host machine must be the same operating system that is used in the Windows container. . If you install a different operating system in the Windows container, the container may load but you will most likely start to see errors, and there is no guarantee that you’ll be able to use all the container’s functionalities.
So, it is very important to make sure that the version of Windows Server 2022 that you install onto the host system is the same version that you run in the Windows container. One nice advantage to using Windows is that you can check what version of Windows you are using. To do so, enter the system’s Registry (Regedit.exe) and search for the following Registry key (see Figure 12.1):
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion.
The host operating system that you are going to run will determine what operating systems you can run in the Windows Server container or Hyper-V container. Not all operating systems are available depending on the host OS image. Table 12.1 shows you all of the supported configurations for each host operating system.
TABLE 12.1 Supported base images
Host operating system | Windows Server container | Hyper- V container |
Windows Server 2022 with Desktop | Server Core/Nano Server | Server Core/Nano Server |
Windows Server 2022 Core | Server Core/Nano Server | Server Core/Nano Server |
Nano Server | Nano Server | Server Core/Nano Server |
Windows 10/11 (Pro/Enterprise) | Not Available | Server Core/Nano Server |
Installing Docker
So the first step in setting up our Windows containers is to install Docker. Docker is the software package that allows you to create and manipulate containers and images.
Docker is the software package that you install and the Docker daemon is the application that you use to do your configuration and management. After you install Docker, the Docker daemon is automatically installed and configured with default settings.
Docker is a third- party application that Microsoft has started using for containers. The Docker application consists of a Docker engine and a Docker client (Docker daemon). So the first thing that we need to do is install Docker. To begin, download and install the Docker application. Another item that needs to be completed when installing and using Docker is making sure that all of the current Microsoft updates have been installed.
In Exercise 12.1, you’ll learn how to download and install Docker. I will also show you how to get your Windows updates. The steps in this exercise install Docker to a Windows Server 2022 (with GUI) Datacenter operating system, but this installation can be done on a Nano Server or a server with no GUI.
EXERCISE 12.1
Installing Docker
- Open an elevated command prompt by clicking the Start button and right-c licking on Windows PowerShell ➢ More ➢ Run As Administrator.
- At the PowerShell prompt, type Sconfig. This will bring up the Server Configuration menu (see Figure 12.2). Choose option 6 by entering 6 and pressing the Enter key to update Windows Server 2022.
FIGURE 12.2 Server Configuration screen
3. A screen should appear asking if you want to install All Updates or Recommended Updates only. Choose A for All Updates and press Enter. If there are any updates available, click A for installing all updates and press Enter. The updates will be downloaded and installed.
4. If there were no updates, go to step 6. After all updates have been installed, choose option 13 to restart the server. You’ll see a message asking if you are sure you want to reboot. Click Yes.
5. Log in and restart PowerShell with administrative rights.
6. At the PowerShell prompt, type the following command and press Enter to download the Docker software:
Install- Module – Name DockerMsftProvider -R epository PSGallery – Force
7. If you get a message that the NuGet provider needs to be installed (see Figure 12.3), choose Y and press Enter. If this message doesn’t appear, go to step 9.
FIGURE 12.3 Install NuGet
EXERCISE 12.1 (continued)
8. If you needed to install NuGet, then reenter the following command:
Install- Module – Name DockerMsftProvider – Repository PSGallery – Force
9. Now that we have downloaded Docker, it’s time to install it. At the PowerShell prompt, type the following command (see Figure 12.4) and press Enter.
Install- Package – Name docker – ProviderName DockerMsftProvider
10. A message will appear stating that the package is not trusted and asking if you want to install software from DockerDefault. Click Y and press Enter.
11. Now that Docker is installed, let’s check for updates again and then reboot. Type Sconfig and choose option 6. Click A for All Updates. If there are any updates, click A for installing All Updates.
12. After the updates complete, you will return to the Server Configuration screen. Choose option 13. Click Yes to reboot.
13. Log into the server.
Docker is now downloaded and installed onto the Windows Server 2022 machine. The next step is to work with Docker to install and configure containers.
When using Docker, there are some switches that you can use. Table 12.2 shows some of the Docker switches and what each switch does. You’ll use these commands to manage Windows or Linux containers using the Docker daemon. These commands can be run in PowerShell or at an elevated command prompt.
Table 12.2 is just a partial list of Docker commands. To see a more complete list, go to Microsoft’s website at https://docs.docker.com/ engine/reference/run. In the left- hand window, the entire list is under Engine (Docker) CLI.
Introduction to Containers 627 | |||
TABLE 12.2 | Docker PowerShell and command- line commands | ||
Command | Description | ||
docker attach | This command allows you to attach to a running container. | ||
docker build | Using this command allows you to build an image from a Docker file. | ||
docker checkpoint | You can use this command to manage a Docker checkpoint. | ||
docker commit | This command allows you to debug and build a new image. | ||
docker container | This command allows you to manage containers. | ||
docker cp | Using this command allows you to copy files and folders between the container and the local computer system. | ||
docker create | This command gives you the ability to create a new container. | ||
docker deploy | You can use this command to create and modify a stack. | ||
docker diff | This command allows you to view changes to files or directories in the container’s filesystem. | ||
docker events | This command allows you to see a server’s events in real time. | ||
docker exec | You can use this command to run a new command in an existing container. | ||
docker image | This command (along with its options) allows you to manage your images. | ||
docker info | Using this command allows you to view system information of the Docker installation. | ||
docker kill | This command allows you to terminate running containers. | ||
docker login | You can use this command to log into the Docker registry of a server. | ||
docker pause | This command allows you to pause all processes within a container. | ||
docker port | Use this command to view the port mappings for a container. | ||
docker ps | This command allows you to view all the containers. | ||
docker pull | You can use this command to pull an image from a registry. | ||
Policy | Result |
no | This setting will not automatically restart the container. This is the default setting for a container. |
on- failure [:max- retries] | This setting will restart the container only if the container has a non- zero exit status. Also, you have the ability to limit the number of restart retries that the Docker daemon will attempt. |
always | This setting will always restart the container. When the setting is set to always, Docker will try to restart the container indefinitely. The container will also always start on daemon startup. |
unless- stopped | This setting will always restart the container unless the container was stopped before the restart. |
TABLE 12.2 Docker PowerShell and command- line commands (Continued)
Command | Description |
docker push | This command allows you to push an image to a registry. |
docker rename | This command allows you to rename a container. |
docker restart | Using this command allows you to restart a container. |
docker rm | You can use this command to remove a container. |
docker run | Using this command (along with the options), you can add to or override the image settings set by a developer. |
docker save | This command allows you to save images to an archive. |
docker search | This command allows you to search the Docker Hub for images. |
docker start | This command allows you to start a stopped container. |
docker stop | This command allows you to stop a running container. |
docker update | You can use this command to update the configuration of a container. |
docker version | This command allows you to view the Docker version information. |
After Docker is installed, you may want to configure the Docker daemon to specify how Docker will start and stop after a system restart or when the system needs to reboot. If you want to set a restart policy, use the – restart flag with the Docker run command.