First Steps: Docker and Containers in Windows Server 2016

Posted on October 28, 2016 by Russell Smith in Windows Server with 0 Comments

Server Hero

In today’s Ask the Admin, I’ll show you how to deploy an image to a container in Windows Server 2016, create a new image and upload it to Docker.

One of the major new features in Windows Server 2016 is support for containers and Docker. Containers provide lightweight and agile virtualization capabilities that developers can use to quickly deploy and update apps, without the overhead associated with virtual machines. And in combination with Docker, a container management solution, container technology has exploded over the past couple of years.

 

 

This is an updated article for information that was previously included in Deploy and Manage Windows Server Containers using Docker that was relevant for Windows Server 2016 Technical Preview 3. For more information on Docker, see What is Docker? and Are Docker Containers Better than VMs? on the Petri IT Knowledgebase.

To follow the instructions in this article, you’ll need access to a physical or virtual server running Windows Server 2016. You can download an evaluation copy of it here from Microsoft’s website, or set up a virtual machine in Microsoft Azure. You’ll also need a free Docker ID, which you can get here by signing up.

Install the Docker Engine

The first step is to install support for Docker in Windows Server 2016.

  • Log in to Windows Server.
  • Click the Search icon in the taskbar and type powershell in the search box.
  • Right-click Windows PowerShell in the search results and select Run as administrator from the menu.
  • Enter administrator credentials as prompted.

Run the following PowerShell cmdlet to install Docker on Windows Server. You’ll be prompted to install NuGet, which downloads the Docker PowerShell module from a trusted online repository.

Now use the Install-Package cmdlet to install the Docker engine on Windows Server. Notice that a reboot is required at the end of the process.

Once the server has restarted, reopen a PowerShell prompt and check that Docker has installed by running the command below:

 

Download an Image from Docker and Start a Container Process

Now that the Docker engine is installed, let’s pull a default Windows Server Core image from Docker:

Pull a Windows Server image from Docker (Image Credit: Russell Smith)

Pull a Windows Server image from Docker (Image Credit: Russell Smith)

Now that the image has been downloaded to the local server, start a container process using docker run:

 

Create a New Image

We can now build a new image using the previously downloaded Windows Server image as a starting point. Before starting, you’ll need a Docker ID. If you don’t already have one, sign up for a Docker account here.

Sponsored

Docker images are usually created from Docker file recipes, but for the purposes of the demonstration, we’ll run a command on the image we downloaded, create a new image based on the change, and then upload it to Docker so that it’s accessible from the cloud.

Modify the image (Image Credit: Russell Smith)

Modify the image (Image Credit: Russell Smith)

Notice in the command line below, the -t parameter gives the image a tag, enabling you to easily identify the image. Furthermore, pay special attention to the hyphen that appears after the tag name.

Once Docker has finished building the new image, check the list of available images on the local server. You should see both microsoft/windowsservercore and mydockerid/windows-test-image in the list.

List the images available on the local server (Image Credit: Russell Smith)

List the images available on the local server (Image Credit: Russell Smith)

Now run the new image in a container, not forgetting to replace mydockerid with your Docker ID name, and you should see Hello World! Appear in the output:

 

Upload an Image to Docker

Let’s upload the image we just created to Docker so that it’s accessible from the cloud. Log in using your Docker ID and password:

Log in to Docker and upload the modified image to the cloud (Image Credit: Russell Smith)

Log in to Docker and upload the modified image to the cloud (Image Credit: Russell Smith)

Use docker push to upload the image we created in the previous steps, replacing mydockerid with your Docker ID name:

If you log in to Docker here, and click Repositories on the home screen, you should see the image you just pushed in the list.

View images available in your repository in the Docker cloud (Image Credit: Russell Smith)

View images available in your repository in the Docker cloud (Image Credit: Russell Smith)

Sponsored

In this article, I showed you how to pull a default Windows Server image from Docker, modify and build a new image, and upload it to a Docker repository.

 

Sponsored

Tagged with , , ,