arrow_back

Create a Container Artifact Registry and Upload Code

Anmelden Teilnehmen
Zugriff auf über 700 Labs und Kurse nutzen

Create a Container Artifact Registry and Upload Code

Lab 30 Minuten universal_currency_alt 1 Guthabenpunkt show_chart Einsteiger
info Dieses Lab kann KI-Tools enthalten, die den Lernprozess unterstützen.
Zugriff auf über 700 Labs und Kurse nutzen

gem-artifact-registry-container

Google Cloud self-paced labs logo

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 Activate Cloud Shell icon 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 YOUR_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.

  2. Your output should now look like this:

Output:

ACTIVE: * ACCOUNT: student-01-xxxxxxxxxxxx@qwiklabs.net 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_ID>

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Overview

In this lab, you'll learn how to create an Artifact Registry repository for storing container images and then push a sample image to it. Artifact Registry provides a central location for managing and securing your container images and other build artifacts. This lab assumes familiarity with Docker and basic Google Cloud concepts.

Task 1. Enable the Artifact Registry API

Before you can use Artifact Registry, you need to enable the API for your project.

  1. Enable the Artifact Registry API.
gcloud services enable artifactregistry.googleapis.com Note:
This command enables the Artifact Registry API for your project.

Task 2. Create an Artifact Registry Repository

Now, create a Docker repository in Artifact Registry to store your container images. You'll need to choose a region for the repository.

  1. Set your project ID:
gcloud config set project {{{ project_0.project_id | "PROJECT_ID" }}} Note:
This command sets your active project identity.
  1. Set your default region to
gcloud config set compute/region {{{ project_0.default_region | "REGION" }}} Note:
This command sets your active compute region.
  1. Create a Docker repository named 'my-docker-repo' in Artifact Registry in the region.
gcloud artifacts repositories create my-docker-repo \ --repository-format=docker \ --location={{{ project_0.default_region | "REGION" }}} \ --description="Docker repository" Note:
This command creates a Docker repository.

Task 3. Configure Docker Authentication

To push and pull images, configure Docker to authenticate with Artifact Registry.

  1. Configure Docker authentication.
gcloud auth configure-docker {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev Note:
This command configures Docker to authenticate with Artifact Registry.

Task 4. Build and Tag a Sample Docker Image

Let's build a simple Docker image and tag it for Artifact Registry. This example uses a simple nginx image.

  1. Create a simple Dockerfile.
mkdir sample-app cd sample-app echo "FROM nginx:latest" > Dockerfile Note:
This creates a basic Dockerfile.
  1. Build the Docker image. Replace with your project ID.
docker build -t nginx-image . Note:
This command builds the Docker image.
  1. Tag the Docker image for Artifact Registry. Replace and with your project ID and region.
docker tag nginx-image {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/my-docker-repo/nginx-image:latest Note:
This command tags the Docker image.

Task 5. Push the Docker Image to Artifact Registry

Now, push the tagged image to your Artifact Registry repository.

  1. Push the Docker image to Artifact Registry. Replace and with your project ID and region.
docker push {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/my-docker-repo/nginx-image:latest Note:
This command pushes the Docker image to Artifact Registry.

Congratulations!

You have successfully created an Artifact Registry repository, built a Docker image, tagged it, and pushed it to Artifact Registry. You can now use this image in your deployments.

Additional Resources

Manual Last Updated Jun 23, 2025

Lab Last Tested Jun 23, 2025

Vorbereitung

  1. Labs erstellen ein Google Cloud-Projekt und Ressourcen für einen bestimmten Zeitraum
  2. Labs haben ein Zeitlimit und keine Pausenfunktion. Wenn Sie das Lab beenden, müssen Sie von vorne beginnen.
  3. Klicken Sie links oben auf dem Bildschirm auf Lab starten, um zu beginnen

Privates Surfen verwenden

  1. Kopieren Sie den bereitgestellten Nutzernamen und das Passwort für das Lab
  2. Klicken Sie im privaten Modus auf Konsole öffnen

In der Konsole anmelden

  1. Melden Sie sich mit Ihren Lab-Anmeldedaten an. Wenn Sie andere Anmeldedaten verwenden, kann dies zu Fehlern führen oder es fallen Kosten an.
  2. Akzeptieren Sie die Nutzungsbedingungen und überspringen Sie die Seite zur Wiederherstellung der Ressourcen
  3. Klicken Sie erst auf Lab beenden, wenn Sie das Lab abgeschlossen haben oder es neu starten möchten. Andernfalls werden Ihre bisherige Arbeit und das Projekt gelöscht.

Diese Inhalte sind derzeit nicht verfügbar

Bei Verfügbarkeit des Labs benachrichtigen wir Sie per E-Mail

Sehr gut!

Bei Verfügbarkeit kontaktieren wir Sie per E-Mail

Es ist immer nur ein Lab möglich

Bestätigen Sie, dass Sie alle vorhandenen Labs beenden und dieses Lab starten möchten

Privates Surfen für das Lab verwenden

Nutzen Sie den privaten oder Inkognitomodus, um dieses Lab durchzuführen. So wird verhindert, dass es zu Konflikten zwischen Ihrem persönlichen Konto und dem Teilnehmerkonto kommt und zusätzliche Gebühren für Ihr persönliches Konto erhoben werden.