Atlantic.Net Blog

How to: Getting started with Windows Containers and Docker

Introduction

This article is a basic primer on how to use Windows Server 2016 with Containers and Docker on the Atlantic.Net Cloud. Docker popularized containers first on Linux, but now with Windows 2016, Windows containers are now natively supported as well. This means you can build your application in a container and ship it across your development and production environments knowing that it will work and run the exact same way on every device.

In this tutorial, we will deploy a web page in an IIS container from a Microsoft-distributed IIS container image. Let’s get started with a quick tutorial!

Deploying an Atlantic.Net Cloud Server

First, we need to deploy a new Windows 2016 with Containers VPS from the Atlantic.Net Cloud.

Atlantic.Net cloud login

  • Click “+ Add Server.”
  • On the “Add a Server” page, enter the following:
  • Server Name: What you’d like your server’s name to be. For example, “Windows 2016 Docker.”
  • Location: The data center you want your server created in.
  • Type: Under the “Operating Systems” tab, select “Windows,” and then select “2016 Datacenter (with Containers/Docker).”

Docker selection

  • Term: Do you want month-to-month, on-demand pricing, or do you want a one or three year term commitment for this server?
  • Plan: We recommended at least a G2.2GB plan size for Windows-based servers, due to memory requirements.
  • Enable Backups: Do you want your server backed up by us daily?
  • Click “Create Server” to begin the provisioning of the server. The next page will have your login credentials for the new server displayed. Please save these somewhere so you can use them to log in. Note: The credentials will also be emailed to you.

Logging in to Windows 2016

Once the server is done provisioning, you will need to log into Windows 2016. Click here to find out how to remotely log in.

Checking Your Docker Version

Ensure that Docker is actually installed by running the “docker version” command from the Windows command prompt (cmd.exe).

C:\Users\Administrator>docker version

Client:
 Version:      17.03.1-ee-3
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   3fcee33
 Built:        Thu Mar 30 19:31:22 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.03.1-ee-3
 API version:  1.27 (minimum version 1.24)
 Go version:   go1.7.5
 Git commit:   3fcee33
 Built:        Thu Mar 30 19:31:22 2017
 OS/Arch:      windows/amd64
 Experimental: false

Running Your First IIS Container

The first step is to retrieve the Microsoft distributed IIS container. We could do this with the docker pull command (ie: docker pull microsoft/iis). However, in the interest of simplicity, we can skip this step and go straight to launching our first container. Docker will automatically pull down the necessary image (and any dependent images) if they don’t already exist locally.

Note: We are going to set some properties of the container when we run the command:

  • Name: The name of the container. In this case, we would specify the name by entering “–name myIIS.”
  • Ports: You can specify what ports you want open on the server. You do this by binding the internal ports of your container to an external port so it is accessible publicly. In this case, we are binding port 80 (the web port) of the container to port 80 of our Cloud Server with “-p 80:80“.

Docker will automatically pull down the necessary image (and any dependent images) if they don’t already exist locally.

C:\Users\Administrator>docker run -d --name myIIS -p 80:80 microsoft/iis
Unable to find image 'microsoft/iis:latest' locally
latest: Pulling from microsoft/iis
3889bb8d808b: Pull complete
6d4d50238ed1: Pull complete
0606d7d474d1: Pull complete
672755d284cd: Pull complete
88f5b9741695: Pull complete
d53dd94c8474: Pull complete
Digest: sha256:bcbcb3b442bc5f0ab3b8b769b52584d98751861b5e438b866d59287cc8112f10
Status: Downloaded newer image for microsoft/iis:latest
2614436cb74c8a21c77e071e13fb5937c12f8946ce8e3c7044e24216cae4100b

Your container is now running, which you can check with the following command:

C:\Users\Administrator>docker ps -a
CONTAINER ID        IMAGE               COMMAND                   CREATED             STATUS              PORTS                NAMES
2614436cb74c        microsoft/iis       "C:\\ServiceMonitor..."   4 days ago          Up 4 days           0.0.0.0:80->80/tcp   myIIS

Next, we will login to the container and start a Windows command prompt (cmd.exe) in the container to enter interactive commands:

C:\Users\Administrator>docker exec -i myIIS cmd
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\>

Now that you are logged into the container, we are going to remove the default IIS web server start page so we can add our own index page:

del C:\inetpub\wwwroot\iisstart.htm

Now add your own content to the index.html page:

echo "Nice! My first container is displaying this text on my index page!" > C:\inetpub\wwwroot\index.html

Now open a browser and type in the IP address of your Cloud Server into the URL field. You should now see your index page:

iis container

Back in the CMD prompt, type exit to exit the interactive session of the container:

C:\>exit
exit

C:\Users\Administrator>

Building and Deploying a Docker Container with Your Changes

Now that the container is configured the way you want, you can save the container to a new container image for future use. First, we need to grab the name of the container from the “docker ps -a” command and stop the container:

C:\Users\Administrator>docker ps -a
CONTAINER ID        IMAGE               COMMAND                   CREATED             STATUS              PORTS                NAMES
2614436cb74c        microsoft/iis       "C:\\ServiceMonitor..."   4 days ago          Up 4 days           0.0.0.0:80->80/tcp   myIIS
C:\Users\Administrator>docker stop myIIS
myIIS

Create the new container with “docker commit <current name> <new image name>“. In our case the current name is “myIIS“:

C:\Users\Administrator>docker commit myIIS configured-iis
sha256:4d08b0a5561e11817d199d6d55d46497ce1d4221384d5c29b4c622d44cceed9c

Verify the new image has been created:

C:\Users\Administrator>docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
configured-iis      latest              4d08b0a5561e        44 seconds ago      10.5 GB
microsoft/iis       latest              9e66ceefdc5a        2 weeks ago         10.4 GB

The container we just created can now be deployed for future use:

docker run -d --name web01 -p 80:80 configured-iis

Now stop the new container and delete it:

C:\Users\Administrator>docker stop web01
web01
C:\Users\Administrator>docker rm web01
web01

Finishing Up

The above was just a basic tutorial.  You can also do interesting things like automating the build of container images using DockerFiles, pushing the images to a centralized repository, and creating redundancy and automatic failover by having multiple nodes setup in a Docker Swarm. Enjoy!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year