If you’re new to Docker and want to learn how to create your first Docker Windows Server container, you’re in luck. In this article, you’ll learn how to get started from scratch – no prior experience is necessary!
Not a reader? Watch this related video.
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.
Download and Install the Docker Module and Package
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.
Once you’ve got the provider installed, it’s now time to put it to good use by installing the Docker page from it.
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!
Downloading the Base Image
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.
Related: How to Create a Docker Windows Image with Docker Build
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.
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!
Running Commands in the Docker Windows Server Container
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.
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.