Artifact Registry is a universal package management service that supports containers and other formats. Learn about transitioning from Container Registry to gain greater flexibility and control over your artifacts.

Quickstart for Container Registry

Container Registry is a private container image registry that runs on Google Cloud.

This quickstart shows you how to:

  • Configure Docker for authentication to Container Registry
  • Tag and push an image to your registry
  • Pull the image from your registry

This quickstart focuses on integration with Docker. For general information about integration with other Google Cloud services, see Using Container Registry with Google Cloud.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  4. Enable the Container Registry API.

    Enable the API

Choose a shell

To complete this quickstart, use either Cloud Shell or your local shell.

Cloud Shell
Cloud Shell is a shell environment for managing resources hosted on Google Cloud. It comes preinstalled with Docker and the gcloud command-line tool, the primary command-line interface for Google Cloud.
Local shell
If you prefer using your local shell, you must install Docker and Cloud SDK in your environment.

Starting Cloud Shell

To launch Cloud Shell, perform the following steps:

  1. Go to Google Cloud Console.

    Google Cloud Console

  2. Click the Activate Cloud Shell button: "".

A Cloud Shell session opens inside a frame lower on the console. You use this shell to run gcloud commands.

Setting up a local shell

To install gcloud and Docker, perform the following steps:

  1. Install the Cloud SDK, which includes the gcloud command-line tool. To update an existing installation, run the command gcloud components update.

  2. Install Docker if it is not already installed.

  3. Docker requires privileged access to interact with registries. On Linux or Windows, add the user that you use to run Docker commands to the Docker security group. This step is not required on MacOS since Docker Desktop runs on a virtual machine as the root user.

    Linux

    The Docker security group is called docker. To add your username, run the following command:

    sudo usermod -a -G docker ${USER}
    

    Windows

    The Docker security group is called docker-users. To add a user from the Administrator command prompt, run the following command:

    net localgroup docker-users DOMAIN\USERNAME /add
    

    Where

    • DOMAIN is your Windows domain.
    • USERNAME is your user name.
  4. Log out and log back in for group membership changes to take effect. If you are using a virtual machine, you may need to restart the virtual machine for membership changes to take effect.

  5. To ensure that Docker is running, run the following Docker command, which returns the current time and date:

  6. docker run busybox date
    

Configure authentication

Before you can push or pull images, you must configure Docker to use the gcloud command-line tool to authenticate requests to Container Registry.

Run the following command:

gcloud auth configure-docker

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

Obtain an image to push

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

  1. Change to a directory where you want to save the image
  2. Run the following command to pull version 1.0 of the image.

    docker pull gcr.io/google-samples/hello-app:1.0
    

Add the image to Container Registry

To add an image to Container Registry, you tag it and then push it to the registry.

Tag the image with a registry name

Tagging the Docker image with a registry name configures the docker push command to push the image to a specific location. For this quickstart, the host location is gcr.io.

Run the following command to tag the image as quickstart-image:tag1:

docker tag gcr.io/google-samples/hello-app:1.0 gcr.io/PROJECT_ID/quickstart-image:tag1

Replace the following:

  • PROJECT-ID is your Google Cloud Console project ID, which you need to add to your command. If your project ID contains a colon (:), see Domain-scoped projects.
  • gcr.io is the hostname
  • quickstart-image is the name of the Docker image
  • 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 Container Registry.

Push the image to Container 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 gcr.io/PROJECT_ID/quickstart-image:tag1

where PROJECT_ID is your Google Cloud Console project ID. If your project ID contains a colon (:), see Domain-scoped projects.

When you push an image to a new host location, the service creates the underlying storage bucket unique to your project. You can view images hosted by Container Registry via the Cloud Console, or by visiting the image's registry name in your web browser: http://gcr.io/PROJECT_ID/quickstart-image.

Pull the image from Container Registry

To pull the image from Container Registry onto your local machine, run the following command:

docker pull gcr.io/PROJECT_ID/quickstart-image:tag1

Replace PROJECT_ID with your Google Cloud Console project ID. If your project ID contains a colon (:), see Domain-scoped projects.

You should see output similar to the following:

latest: Pulling from my-project/quickstart-image:tag1
Digest: sha256:70c42...
Status: Image is up to date for gcr.io/my-project/quickstart-image:tag1

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.

Run the following command to delete the Docker image from Container Registry.

gcloud container images delete gcr.io/PROJECT_ID/quickstart-image:tag1 --force-delete-tags

Replace PROJECT_ID with your Google Cloud Console project ID. If your project ID contains a colon (:), see Domain-scoped projects.

What's next