Working with Custom Images on Google Compute Engine

1 hour
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we are going to practice creating custom images from two versions of a web server (which will be provided for you), add both images to the same image family, describe the image family, deprecate an image, and create a new web server from our custom images.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create Image from base-apache Instance Using Web Console

Create the custom image from the base-apache instance using the web console:

  • Stop the instance.
  • Go to Compute Engine > Images.
  • Click CREATE IMAGE
  • Name image webserver-base.
  • In the Source dropdown menu, select Disk.
  • In the Source disk dropdown menu, select base-apache.
  • Leave the location as multi-region.
  • Set Family to webserver.
  • Click Create.
Create Image from custom-webpage Instance Using gcloud Command

Create an image from the custom-webpage instance using the gcloud command:

  • Stop the instance.
  • Open Cloud Shell.
  • Enter command to create image from the custom-webpage disk, name the image custom-webpage, and add to the webserver image family:
    • gcloud compute images create custom-webpage --source-disk=custom-webpage --source-disk-zone=us-central1-a --family=webserver
  • Verify that image is created and located in the appropriate family using the web console.
View Images in Web Console and View webserver Image Family Information in Command Line

View the images in the web console and view the webserver image family information in the command line:

  • In web console, go to Compute Engine > Images.
  • To describe the image family and view the latest image, enter this command:
    • gcloud compute images describe-from-family webserver
  • The shown image is the latest version.
Deprecate Base Image in Our webserver Image Family Using Command Line

Deprecate the base version using the command line:

  • First, view the process in the web console:
    • Go back to Compute Image > Images.
    • Place check next to webserver-base, and click DEPRECATE from the three-dot icons on the far right.
    • Set State to Deprecated, and set Replacement as custom-page-1.
    • Cancel out and do the same thing via command line.
  • In Cloud Shell, enter:
    • gcloud compute images deprecate webserver-base --state DEPRECATED
  • Verify in the web console.
Create a New Web Server from Custom Image

Create a new web server from the custom image:

  • Go to Compute Engine > VM Instances.
  • Click Create Instance.
  • Place it in any region and zone you want.
  • Name the instance new-web-server
  • In the Machine configuration section, choose the ec2-micro Machine type.
  • Under Boot disk, click Change.
  • Click on Custom images from the top menu.
  • Click on Show deprecated images to view all images.
  • Select custom-webpage, and click Select.
  • Check the box for Allow HTTP traffic under Firewall settings.
  • Click Create.
  • Once the instance is up, click the external IP address to verify the new web page works.

Additional Resources

Be sure to launch the lab in incognito (or other private view) mode to avoid cached login issues.

You will have two custom web servers created in Compute Engine for you when you begin the lab.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?