Jump to Content
Google Cloud

How to run Windows Containers on Compute Engine

April 2, 2018
Mete Atamel

Cloud Developer Advocate

Container virtualization is a rapidly evolving technology that can simplify how you deploy and manage 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.

For a long time, you could only containerize Linux processes, but Microsoft introduced support for Windows-based containers in Windows Server 2016 and Windows 10. With this, you can now take an existing Windows application, containerize it using Docker, and run it as an isolated container on Windows. Microsoft supports 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.

Windows containers, meet Google Cloud


Google Cloud provides container-optimized VM images that you can use to run containers on Compute Engine. We also offer a Windows VM image for containers that comes with Docker, microsoft/windowsservercore, and microsoft/nanoserver base images installed.

To run Windows containers on Compute Engine, first you need a Windows VM. In Google Cloud Platform Console, go to the Compute Engine section and create an instance. Make sure you’ve selected Windows Server version 1709 Datacenter Core for Containers (Beta) for the boot disk.

https://storage.googleapis.com/gweb-cloudblog-publish/images/image1ujir.max-600x600.PNG

After you’ve created the instance, create a new Windows password either from the console or gcloud and RDP into the VM. Once inside the VM, you’ll notice that it’s a bare-minimum OS with a minimal UI. The good news is that Docker and the base images are already installed; that’s all you need to run Windows containers.

https://storage.googleapis.com/gweb-cloudblog-publish/images/image2eg8w.max-700x700.PNG

For the first Windows container, let’s create a HelloWorld PowerShell script that we can call, similar to this example.

The microsoft/nanoserver:1709 image is already installed, but that image does not include PowerShell. Instead, there's a microsoft/powershell image based on microsoft/nanoserver:1709 image that we can use.

First, let’s pull the PowerShell image and run it:

Loading...

This takes us inside the PowerShell container. Now, we can create a HelloWorld PowerShell script and exit the container:

Loading...

We now need to create a new image that has the PowerShell script, using the modified container. Get the container ID and create a new container image with that ID using the docker commit command:

Loading...

Finally, we can run the image by pointing to the script inside the container:

Loading...

There you go, you’re running a Windows container on GCP!
If you want to try the steps on your own, we have a codelab you can try out:

https://storage.googleapis.com/gweb-cloudblog-publish/images/image3yhng.max-400x400.PNG
Video Thumbnail

Just don’t forget to to shut down or delete the VM when you’re done experimenting, to avoid incurring charges!
To learn more about Windows containers and Windows on GCP, check out our documentation. And if you have feedback or want to know more, drop us a note in the comments.

Posted in