Although Docker is best known for hosting Linux containers, you can also use it to host Windows containers. Microsoft created a version of Windows Server called Nano Server specifically for containerized environments. In this article, you’ll learn how to create Nano Server-based Docker containers.
Before we discuss this, you need to know Microsoft has made significant changes to Nano Server over the years. The instructions that I provide in this article apply only to Windows Server 2019 and above. Let’s get started with getting the prerequisites!
Install the Prerequisites
Nano Server is intended for use solely as a container role. As such, you need to configure your Windows Server to run Docker before the internet information services (IIS) based Nano Server. To do so, follow these steps:
- Install the Hyper-V feature. To do this, open an elevated PowerShell session and enter:
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
- Install the container feature after the server reboots. Enter this command into an elevated PowerShell window:
Install-WindowsFeature containers -Restart
- Open an elevated PowerShell session once the reboot is complete. Install the Docker Microsoft Package Management Provider module by using this command:
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
- Install Docker by entering this command:
Install-Package -Name docker -ProviderName DockerMsftProvider
- Start the Docker service by entering the following command:
- Verify that Docker is working by entering this command:
Now let’s get the Nano Server package next!
Acquiring a Nano Server Package
Now that Docker is up and running, the next step is to locate a Nano Server package compatible with your system.
- Open an elevated PowerShell session and enter the following command:
docker search nanoserver
- Check for a Nano Server image that meets your needs. I’m going to use the compulim.nanoserver-node image
- Pull the Docker image next. As you look at the figure above, you’ll notice that nothing listed says “Nano Server”. However, the very first entry on the list is NanoServer/iis. NanoServer is the name of the base image. You can pull this base image by entering the following command:
Docker pull mcr.microsoft.com/windows/nanoserver:1809
Even though the command shown above isn’t super intuitive, its madness is methodical. “Mcr.microsoft.com” is the name of the Microsoft container registry. The Nano Server base image is located in the Windows path.
The “:1809” that appears at the end of the docker pull is important. 1809 is the version of Windows Server 2019 that I’m running on my Docker host. Appending 1809 to the docker pull tells Windows to download an image that’s based on Windows version 1809. Without this, you’ll likely download an incorrect version, and you won’t be able to create containers from the image.
Launching Nano Server
Now that you’ve pulled the Nano Server image containing IIS, the only thing left to do is to launch a container based on the image. To do so, you’ll need to know the exact name of the image.
- Get the image name by entering this command:
Docker image ls
- Launch a container based on the image. In this case, the command is:
Docker run -it mcr.microsoft.com/windows/nanoserver:1809
The -it portion of the command tells Windows that you want to run the command interactively, which causes the Nano Server container to launch and then open a Windows Command Line prompt inside of the container image.
While it isn’t very difficult to create Nano Server containers, you must download the correct version of the container image. Follow the steps I’ve outlined above to ensure you create a Nano Server container without any hitches.
Do you have more questions about Nano Server containers? Check out the FAQ and Resources sections below.
Why does the Docker version command return an error?
If you receive an error message when entering the Docker version command check the following. First, ensure the Docker service is running by using the “Start-Service” Docker command. Next, ensure you used a lowercase “v” in the word version. Docker is case-sensitive, and entering the word version with an uppercase “V” will result in an error.
Why am I receiving an error stating that the NuGet provider is required?
NuGet downloads and tracks package updates for software developers to ensure the correct dependencies are used when creating software solutions. It also enables you to access your own packages when working remotely. You must install NuGet for programs to access NuGet packages. Developers can help others by creating their own packages and allowing other developers to use them with NuGet.
What happens if you attempt to launch a container from an image based on a version of Windows different from the one running on the host?
If you try to launch a container from an incorrect image version, like using a Windows Server 2016 base image on a Windows Server 2019 host, you’ll get an error response from the daemon. The error message will usually include the text “the container operating system does not match the host operating system”.
What happens if you omit the operating system version from the container image name?
The operating system version that appears at the end of an instance is treated as a tag. If you omit the tag, Windows will use a default tag called “Latest”. The Latest tag corresponds to the most recently created version of that particular image. In most cases, the Latest image is based on Windows Server 2016.
Is Microsoft doing anything to make the container version mismatch issue less problematic?
According to Microsoft, you won’t have to worry about the version mismatch issue if the container host and the container image are both running Windows version 1809 or higher, thanks to a modular coding approach. To this end, it makes sense to check you’re working with higher versions of these platforms.
TechGenix: Article on Creating Nano Server Images on Hyper-V
Learn how to create legacy Nano Server images on Hyper-V.
TechGenix: Article on Nano Server Deployment
Find out how to deploy Nano Server using System Center Virtual Machine Manager.
TechGenix: Article on What a Nano Server Is
TechGenix: Article on What You Need to Know about Nano Servers
Read more on the top things you need to know about Nano Server.
TechGenix: Article on How to Configure a Nano Server
Learn how to configure a Nano Server after deployment.