How to Deploy Windows Nano Server in Docker Containers

Image of container homes.
Modular yet functional environments; is this a Nano Server container?
SOURCE: Trinity Bouy Wharf

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:

  1. Install the Hyper-V feature. To do this, open an elevated PowerShell session and enter:

 Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart

  1. Install the container feature after the server reboots. Enter this command into an elevated PowerShell window: 

Install-WindowsFeature containers -Restart

  1. 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

  1. Install Docker by entering this command: 

Install-Package -Name docker -ProviderName DockerMsftProvider

Image of Windows PowerShell.
Use the Install-Package cmdlet to install Docker.
  1. Start the Docker service by entering the following command: 

Start-Service Docker

  1. Verify that Docker is working by entering this command: 

docker version

Image of Windows PowerShell.
You can use the Docker version command to verify that Docker is working.

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.

  1. Open an elevated PowerShell session and enter the following command: 

docker search nanoserver

  1. Check for a Nano Server image that meets your needs. I’m going to use the compulim.nanoserver-node image
Image of Windows PowerShell.
Use the Docker search nanoserver command to see a list of the available images.
  1. 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

Image of Windows PowerShell.
You will need to use the Docker pull command to retrieve the image.

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. 

  1. Get the image name by entering this command: 

Docker image ls

Image of Windows PowerShell.
The Docker image ls command lists container images that have been downloaded.
  1. 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.

Image of Windows PowerShell.
This is what a Nano Server container looks like when it is running interactively.

Final Thoughts

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.

FAQ

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.

Resources

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

Discover why Nano Server has such a tiny footprint.

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.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top