Learn how to create a Docker container on a Windows Server 2016 host in this step-by-step how-to post.

Windows Server has come a long way since Windows NT. First, we could virtualize Windows Server, and now we can even play in the realm which what was once an exclusive Linux feature: containers!

Nowadays, we can bring up a Windows Server container in Docker just as easily as a Linux container, but how? Since Microsoft is a fairly recent player in the container market, the concept of Docker and containers is probably new to a lot of Microsoft shops. The best way to learn about something is doing, so let's do it.

For this article, we're going to start from a Windows Server 2016 host since this is the earliest version of Windows in which you can run a true Docker host.

On your Windows Server 2016, head out to the PowerShell Gallery and download the DockerMsftProvider module. This is the PowerShell module that contains all of the package providers that will allow you to download and install the docker utilities via the PowerShellGet Install-Package command.

PS> Install-PackageProvider -Name NuGet -MinimumVersion -Force
PS> Install-Module -Name DockerMsftProvider -Force

Once you've got the provider installed, it's now time to put it to good use by installing the Docker page from it.

PS> Install-Package -Name docker -ProviderName DockerMsftProvider -Force

WARNING: A restart is required to enable the containers feature. Please restart your machine.
Name    Version        Source            Summary
----    -------        ------            -------
Docker	17.06.2-ee-6   DockerDefault    Contains Docker EE for use with Windows Server.

We will head the warning the package installer tells us and will then restart our Windows Server host with Restart-Computer -Force.

Once the server comes back online, check to see if the docker daemon is working correctly by checking the version. If you get back a client and a server section with version information for each, you're good to go!

PS> docker version
Version: 17.06.2-ee-6
API version: 1.30
Go version: go1.8.3
Git commit: e75fdb8
Built: Mon Nov 27 22:46:09 2017
OS/Arch: windows/amd64

Version: 17.06.2-ee-6
API version: 1.30 (minimum version 1.24)
Go version: go1.8.3
Git commit: e75fdb8
Built: Mon Nov 27 22:55:16 2017
OS/Arch: windows/amd64
Experimental: false

Next comes the part where you need a container image. The easiest way to get an image onto your server is through the Docker Hub. To get an image from the Docker Hub, you can use the pull parameter on the docker utility.

For now, I'll pull down a fresh copy of Windows Server Core. Once started, you will see the download progress for each image in the defined repository.

PS> docker pull microsoft/windowsservercore

Using default tag: latest
latest: Pulling from microsoft/windowsservercore
3889bb8d808b: Downloading [========================> ] 2.019GB/4.07GB
cfb27c9ba25f: Download complete

Once the image(s) have been downloaded, Docker will then extract each image from its compressed state. Unfortunately, for Windows Server images, this can take a bit of time. But once the image(s) have extracted, you've created your first Windows Server container with Docker!

The final piece just to confirm the container is intact and working is to send a run command to it using docker run. docker run is a command that sends a non-interactive command to the container. It's essentially like opening up cmd and running commands that way.

Any command will work so for how we'll just see if we can return the hostname of the container using the hostname command.

PS> docker run microsoft/windowsservercore

If it returns anything but an error you're done! You've now got a Windows Server 2016 host setup with the Docker service running capable of pulling and pushing Docker images to/from the Docker Hub and running any number of containers you please.

Join the Jar Tippers on Patreon

It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!

Become a Patron!