Loading...
No results found.

Google Cloud Skills Boost

Apply your skills in Google Cloud console

Implement DevOps Workflows in Google Cloud

Get access to 700+ labs and courses

Artifact Registry: Qwik Start

Lab 30 minutes universal_currency_alt 1 Credit show_chart Introductory
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

GSP1131

Overview

Artifact Registry is a secure, scalable, and fully managed service for storing, managing, and securing your build artifacts and dependencies. You'll learn how to create a private Docker repository, configure authentication, and push and pull a sample Docker image. This hands-on experience will give you a foundational understanding of how to use Artifact Registry for your containerized applications.

Objectives

In this lab, you will learn how to perform the following tasks:

  • Create a private Docker repository in Artifact Registry
  • Set up authentication
  • Push an image to the repository
  • Pull the image from the repository

Prerequisites

Some experience with Docker is recommended for this lab. Feel free to check out the Docker documentation for a refresher or introduction. You can also check out our Introduction to Docker lab for more hands-on practice!

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 Cloud 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 Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    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 below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details panel.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details panel.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. 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 Google Cloud console opens in this tab.

Note: To view a menu with a list of Google Cloud products and services, click the Navigation menu at the top-left.

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell at the top of the Google Cloud console.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Create a Docker repository

In this section, you'll create a private Docker repository within Artifact Registry. This repository will serve as a central location to store and manage your Docker images. You'll use the gcloud command-line tool to create the repository and then verify its creation through the Google Cloud Console.

  1. Open a new Cloud Shell window by clicking the icon () in the top right corner of the console.

  2. Run the following command to get your Project ID and save it as an environment variable:

export PROJECT_ID=$(gcloud config get-value project)
  1. Run the following command to create a new Docker repository named example-docker-repo in the location with the description "Docker repository".
gcloud artifacts repositories create example-docker-repo --repository-format=docker \ --location={{{project_0.default_region | Region}}} --description="Docker repository" \ --project=$PROJECT_ID
  1. Run the following command to verify that your repository was created.
gcloud artifacts repositories list \ --project=$PROJECT_ID
  1. From the search bar at the top of the console, type Artifact Registry and select the first result.

  2. On the Artifact Registry product page, verify you can see your repository. It should resemble the following:

  1. Click the example-docker-repo repository. You should notice there are no files inside the repository. In the next sections, you will be adding files to the repository.
You can also create repositories from the Artifact Registry product page by clicking the Create Repository button and following the same steps as above.

Click Check my progress to verify the objective. Create a Docker repository.

Task 2. Configure authentication for Artifact Registry

To push and pull images from your newly created Docker repository, you need to configure Docker to authenticate with Artifact Registry. This involves setting up credentials that allow your Docker client to interact with the repository securely.

Before you can push or pull images, you will need to configure Docker to use the Google Cloud CLI to authenticate requests to Artifact Registry.

  1. To set up authentication to Docker repositories in the region , run the following command:
gcloud auth configure-docker {{{project_0.default_region | Region}}}-docker.pkg.dev

The command updates your Docker configuration. You can now connect with Artifact Registry in your Google Cloud project to push and pull images.

For information about other authentication methods, see Authentication methods.

Task 3. Obtain an image to push

You'll need a Docker image to work with in this lab. Instead of building an image from scratch, you'll pull a pre-built sample image from a public repository. This will allow you to focus on interacting with Artifact Registry.

For this lab, you will push a sample image named hello-app.

  1. Run the following command to pull version 1.0 of the image.
docker pull us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0

Image paths in Artifact Registry include multiple parts. For this sample image:

  • us-docker.pkg.dev is the hostname for container images stored in Artifact Registry Docker repositories, which includes the location of the repository (us).
  • google-samples is the project ID.
  • containers is the repository ID.
  • /gke/hello-app is the path to the image in the repository containers.

Task 4. Add the image to the repository

Now you'll add the sample image to your private repository. This involves tagging the image with the repository name to specify its destination and then pushing it to Artifact Registry.

Before you push the Docker image to Artifact Registry, you must tag it with the repository name.

Tag the image with a registry name

Tagging the image ensures it's pushed to the correct location, which for this lab is -docker.pkg.dev.

  1. Run the following command to tag the image as sample-image:tag1:
docker tag us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 \ {{{project_0.default_region | Region}}}-docker.pkg.dev/$PROJECT_ID/example-docker-repo/sample-image:tag1

Where:

  • is the repository location.
  • -docker.pkg.dev is the hostname for the Docker repository you created.
  • $PROJECT_ID is your Google Cloud Project ID.
  • example-docker-repo is the ID of the repository you created.
  • sample-image is the image name you want to use in the repository. The image name can be different than the local image name. For this lab you will store the image directly under the repository ID example-docker-repo.
  • tag1 is a tag you're adding to the Docker image. If you didn't specify a tag, Docker will apply the default tag latest.

You are now ready to push the image to the repository you created.

Push the image to Artifact Registry

After you have configured authentication and tagged the local image, you can push the image to the repository that you created.

To push the Docker image, run the following command:

docker push {{{project_0.default_region | Region}}}-docker.pkg.dev/$PROJECT_ID/example-docker-repo/sample-image:tag1

Click Check my progress to verify the objective. Add the image to the repository.

Task 5. Pull the image from Artifact Registry

Finally, you'll pull the image that you just pushed to your private repository. This simulates how you would access and use images stored in Artifact Registry in a real-world scenario.

  1. To pull the image from Artifact Registry onto your local machine, run the following command:
docker pull {{{project_0.default_region | Region}}}-docker.pkg.dev/$PROJECT_ID/example-docker-repo/sample-image:tag1

You should see output similar to the following:

latest: Pulling from [PROJECT-ID]/sample-image:tag1 Digest: sha256:70c42... Status: Image is up to date for {{{project_0.default_region | Region}}}-docker.pkg.dev/$PROJECT_ID/example-docker-repo/sample-image:tag1

Congratulations!

In this lab, you successfully created a private Docker repository in Artifact Registry, configured authentication, pushed a sample image to the repository, and pulled the image back down. You now have a basic understanding of how to use Artifact Registry to manage your Docker images.

Next steps / learn more

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 November 28, 2024

Lab Last Tested November 28, 2024

Copyright 2024 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.

Previous Next

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

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.
Preview