Container images that are based on nano server must be run as hyper-v containers.

GSP153

Container images that are based on nano server must be run as hyper-v containers.

Overview

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.

You can 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 containersdocumentation.

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, and microsoft/nanoserver base images installed.

In this lab you will create a container app and deploy the container app to Compute Engine.

What you'll learn

  • Create a Windows Server VM for containers on Compute Engine.

  • Create a HelloWorld Windows container app.

  • Containerize the app using Docker.

  • Run the Windows container app on Compute Engine.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

How to start your lab and sign in to the Google Cloud Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:

    • The Open Google Console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.

  4. Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.

    Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  5. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Cloud Console opens in this tab.

Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left.

Task 1. RDP into the Windows VM

  1. From the Navigation menu click on Compute Engine. Here you'll see a Windows VM provisioned for you.

  2. Log into the Windows VM by clicking the RDP button of the VM (or use your own RDP client if you like):

You'll be asked to either downlowd a Chrome RDP Extension or download the RDP file in order to connect.

  1. Follow the on-screen instructions for connecting for the method you're using.

  2. Use credentials provided in connection details for logging in:

Once inside the Windows VM, you'll notice that it's a bare-minimum OS with minimal UI.

Note: If the command line window is not open, open it by going to Task Manager: Ctrl + Alt + Delete and choose Task Manager. Then, go to File > Run new task > cmd.
  1. In the Windows command prompt (C:\Users\gcpstagingXXXXX_stud>), run the following to see the images that are installed by default:

docker images

Output:

REPOSITORY TAG IMAGE ID mcr.microsoft.com/windows/servercore ltsc2019 29a2c2cb7e4d

Copy and paste with the RDP client

Once you are securely logged into your instance, you may find yourself copying and pasting commands from the lab manual.

To paste, hold the CTRL-V keys (if you are a Mac user, using CMND-V will not work.) If you are in a Powershell window, be sure that you have clicked into the window or else the paste shortcut won't work.

If you are pasting into putty, right click.

Task 2. Create a Windows container app

For the app inside the Windows container, use an IIS Web Server. IIS has an image for Windows Server 2019. You can use the image as is and it will serve the default IIS page, but fot this lab, do something more interesting and have IIS serve a page you define.

Your folder and file structure should look like:

C:\my-windows-app>dir /s /b C:\my-windows-app\content C:\my-windows-app\Dockerfile C:\my-windows-app\content\index.html
  1. Create a folder called my-windows-app and enter into the directory:
mkdir my-windows-app cd my-windows-app
  1. Create folder named content, a file named index.html within it:
mkdir content call > content\index.html
  1. Edit the dockerfile:
notepad content\index.html
  1. Add the following content in index.html:

Windows containers

Windows containers are cool!

  1. Save the index.html

This is the page IIS will serve.

Task 3. Build Docker image

  1. Create a Dockerfile for the Docker image:
call > Dockerfile
  1. Edit the dockerfile:
notepad Dockerfile

You're using the IIS Container image version compatible with Windows Server 2019.

  1. Add the following contents in the Dockerfile:
FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019 RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\* WORKDIR /inetpub/wwwroot COPY content/ .
  1. Save the Dockerfile.

  2. Build the Docker image and tag it with Google Container Registry (GCR) and your project id. This will be useful when we push the image to GCR later (replace dotnet-atamel with your GCP Project ID):

docker build -t gcr.io/dotnet-atamel/iis-site-windows .

Once the Docker image is built, you can see it along with its IIS dependency:

docker images

Sample output:

REPOSITORY TAG gcr.io/dotnet-atamel/iis-site-windows latest mcr.microsoft.com/windows/servercore/iis windowsservercore-ltsc2019 mcr.microsoft.com/windows/servercore ltsc2019

Click Check my progress below to verify you're on track in this lab.

Build Docker image

Task 4. Run the Windows container

You're now ready to run the Windows container.

  1. Inside Command Prompt, run the container and expose it on port 80 (replace dotnet-atamel with your GCP Project ID):

docker run -d -p 80:80 gcr.io/dotnet-atamel/iis-site-windows
  1. You can check that the container is running:

docker ps

Sample output:

CONTAINER ID IMAGE 3d7c71a258ce gcr.io/dotnet-atamel/iis-site-windows

To see the web page, go to the External IP column of Compute Engine instance and simply open it with HTTP in the browser:

Note: This setup is not ideal for production. It does not survive server restarts or crashes. In a production system, you want to get a static IP for your VM and have a startup script to start the container. This will take care of server restarts but doesn't help so much for server crashes.

Task 5. Cleanup

  1. Type exit to leave the VM.

  2. Close the RDP window by clicking the X in the top right corner and confirm that you want to be disconnected.

When you are done with experimenting with Windows containers, it is a good idea to either stop or delete the VM you created.

  1. To delete the VM, go back to the Console and click the three dots in the right-hand menu and select Delete.

Congratulations!

What was covered

  • Create a Windows Server VM for containers on Compute Engine

  • Create a HelloWorld Windows container app

  • Containerize the app using Docker

  • Run the Windows container app on Compute Engine

Finish your quest

This self-paced lab is part of the Windows on Google Cloud quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll or any quest that contains this lab and get immediate completion credit. See the Google Cloud Skills Boost catalog to see all available quests.

Take your next lab

Continue your quest with Install and Use Cloud Tools for PowerShell, or check out these suggestions:

  • Compute Engine: Qwik Start

Next steps

  • An example of Windows Container on Windows 10.
  • Learn more about Windows containers on Google Cloud.
  • Learn more about Windows on Google Cloud.
  • Learn more about .NET on Google Cloud.

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual last updated October 3, 2022

Lab last tested May 19, 2022

Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Does Docker require Hyper

Docker requires that the Hyper-V feature is enabled, so if necessary will ask you to enable it and restart. Click OK for Docker to enable Hyper-V and restart your system.

Can Hyper

With Hyper-V isolation, multiple container instances run concurrently on a host; however, each container runs inside of a highly optimized virtual machine and effectively gets its own kernel. The presence of the virtual machine provides hardware-level isolation between each container as well as the container host.

Why would you want to use Hyper

Since Hyper-V containers provide much greater isolation between running containers, this allows for a much-improved security stance when compared to simply running traditional Windows Server containers.

How are Windows containers different from Hyper

Although Windows Server containers and Hyper-V containers do the same thing and are managed the same way, the level of isolation they provide is different. Windows Server containers share the underlying OS kernel, which makes them smaller than VMs because they don't each need a copy of the OS.