Container virtualization is a fast evolving technology, which aims to simplify the deployment and management of distributed applications. When people discuss containers, they usually mean Linux-based containers. This makes sense, because native Linux kernel features like cgroups introduced the idea of resource isolation, eventually leading to containers as we know them today. Until recently, only Linux processes could be containerized, but Microsoft introduced support for Windows-based containers in Windows Server 2016 and Windows 10.

It is now possible to take an existing Windows application, containerize it using Docker, and run it as an isolated container on Windows. There are two flavors of Windows containers: Windows Server and Hyper-V. You can build Windows containers on either the microsoft/windowsservercore and microsoft/nanoserver base images. You can read more about Windows containers in the Microsoft Windows containers documentation.

Google Cloud provides container-optimized VM images on which to run containers on Compute Engine. There is also a Windows VM image for containers. It comes with Docker, microsoft/windowsservercore base images installed.

What you'll learn

What you'll need

How will you use this tutorial?

Read it through only Read it and complete the exercises

How would rate your experience with Google Cloud Platform?

Novice Intermediate Proficient

For this codelab, you need a Google Cloud Platform project to interact with PowerShell. If you have an existing project, you can either use that or you can create a new project using the following steps.

Self-paced environment setup

If you don't already have a Google Account (Gmail or GSuite), you must create one. Sign-in to Google Cloud Platform Console (console.cloud.google.com) and create a new project:

Remember the project ID, a unique name across all Google Cloud Platform projects. It will be referred to later in this codelab as PROJECT_ID.

Next, you'll need to enable billing in Google Cloud Platform Console in order to use Google Cloud Platform resources like Google Cloud Datastore and Cloud Storage.

New users of Google Cloud Platform are eligible for a $300 free trial. Running through this codelab shouldn't cost you more than a few dollars, but it could be more if you decide to use more resources or if you leave them running (see the "cleanup" section at the end of this document).

To run Windows containers on Google Cloud, you first need a Windows VM.

In Google Cloud Platform Console, go to the Compute Engine section and create an instance. Make sure you choose Window Server 2019 Datacenter Core for Containers version is selected for the boot disk:

Window Server 2019 Datacenter Core for Containers is the minimal installation of Windows Server Datacenter optimized for running containers.

Also make sure that HTTP and HTTPS traffic is enabled to the VM. This is important for Docker on the VM to be able to pull images:

After you press "Create", it takes a couple of minutes or so for the VM to start up. After the VM has started, you should see your VM running like the following image:

Before you can remote desktop (RDP) into the VM, you need to create a Windows password. There are two ways of doing this. You can either set a new Windows password from the RDP button:

Another way is to click View gcloud command to reset password and run the command displayed in the dialogue in Cloud Shell:

After a few seconds, you should see the Windows password in console or Cloud Shell. Make sure you make a secure note of it for the next step.

Now, log into the Windows VM. You can simply click on the RDP button of the VM (or use your own RDP client if you like):

Once inside the VM, notice that it's a bare-minimum OS with minimal UI. There should be a command line window open but if not, you can open Task Manager with Ctrl + Alt + Delete and Task Manager. Then, you can go to File > Run new task > cmd.

In the command prompt, you can see that Docker and servercore image is installed by default:

C:\> docker images

REPOSITORY                             TAG                     IMAGE ID
mcr.microsoft.com/windows/servercore   ltsc2019                3e9dc86c64a9

For the first Windows container, we will download a pre-created .NET sample image from the Docker Hub registry and deploy a simple container running a .Net Hello World application as explained in this example from Windows container docs.

Run the following command:

C:\> docker run microsoft/dotnet-samples:dotnetapp-nanoserver-1809

This will first pull the .NET sample image:

dotnetapp-nanoserver-1809: Pulling from microsoft/dotnet-samples
6a5e981230da: Pull complete
7fe5fc4b6b6d: Pull complete
e246797eaa11: Pull complete
1e66b88a6a25: Pull complete
bc612261b431: Pull complete
ea0ba5e33e76: Pull complete
ba41b7656325: Pull complete
9bfe3aa1173c: Pull complete
7bd4fabc8b3d: Pull complete
c2f01337e7f7: Pull complete
Digest: sha256:165c5b3782b4127d7aa8430523117d3f4d1ca603ae2ff8160339481a0aff9f3a
Status: Downloaded newer image for microsoft/dotnet-samples:dotnetapp-nanoserver-1809

Then, it will run it as a container where it simply prints a Hello World message and exits:

   Hello from .NET Core!
      __________________
                        \
                        \
                            ....
                            ....'
                            ....
                          ..........
                      .............'..'..
                  ................'..'.....
                .......'..........'..'..'....
                ........'..........'..'..'.....
              .'....'..'..........'..'.......'.
              .'..................'...   ......
              .  ......'.........         .....
              .                           ......
              ..    .            ..        ......
            ....       .                 .......
            ......  .......          ............
              ................  ......................
              ........................'................
            ......................'..'......    .......
          .........................'..'.....       .......
      ........    ..'.............'..'....      ..........
    ..'..'...      ...............'.......      ..........
    ...'......     ...... ..........  ......         .......
  ...........   .......              ........        ......
  .......        '...'.'.              '.'.'.'         ....
  .......       .....'..               ..'.....
    ..       ..........               ..'........
            ............               ..............
          .............               '..............
          ...........'..              .'.'............
        ...............              .'.'.............
        .............'..               ..'..'...........
        ...............                 .'..............
        .........                        ..............
          .....


**Environment**
Platform: .NET Core
OS: Microsoft Windows 10.0.17763

That's it! You just ran your first Windows Container on Compute Engine!

If you check Docker images again, you will see the downloaded image for the sample:

C:\> docker images

REPOSITORY                             TAG                     IMAGE ID
mcr.microsoft.com/windows/servercore   ltsc2019                3e9dc86c64a9
microsoft/dotnet-samples           dotnetapp-nanoserver-1809   d14c2b1ef740

When you are done with experimenting with Windows containers, it is a good idea to either stop or delete the VM you created to avoid incurring charges. To delete the VM, go to Compute Engine VM instances page and select Delete from the menu for the VM you want to delete:

What we've covered

Next Steps