If you’re new to Docker and want to learn how to create your first Docker Windows container, you’re in luck. In this article, you’ll learn how to get started from scratch – no prior experience necessary!
If you’re more of a visual learner, check out this post’s related TechSnips video demonstrating the same techniques.
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 run Windows on a container in Docker just as easily as a Linux-based 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
PS> Install-PackageProvider -Name NuGet -MinimumVersion 188.8.131.52 -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
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 Client: 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 Server: 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 base 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 for Windows has been downloaded, the Docker engine 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 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
PS> docker run microsoft/windowsservercore hostname69c7de26ea48
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.