Quickstart for Container Registry

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

This quickstart shows you how to:

  • Set up authentication
  • Push an image to your project's Container Registry
  • Pull the image from your project's Container Registry

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Cloud Console, on the project selector page, select or create a Cloud project.

    Go to the project selector page

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

  4. Enable the Container Registry API.

    Enable the API

  5. Install and initialize the Cloud SDK.
  6. Install Docker. If you're using a Linux-based operating system, such as Ubuntu or Debian, add your username to the docker group so that you can run Docker without using sudo:
    sudo usermod -a -G docker ${USER}

    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.

  7. Open Docker. To ensure that Docker is running, run the following Docker command, which returns the current time and date:
  8. docker run busybox date

For this quickstart, use either Cloud Shell or any environment where the Cloud SDK is installed.

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. To do so, run the following command (you are only required to do this once):

gcloud auth configure-docker

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

Tag the image with a registry name

Before you push the Docker image to Container Registry, you need to tag it with its 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 hello-app:1.0 gcr.io/[PROJECT-ID]/quickstart-image:tag1

where:

  • [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

Once docker has been configured to use gcloud as a credential helper, and the local image is tagged with the registry name, you can push it to Container Registry.

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

where [PROJECT-ID] is 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 [PROJECT-ID]/quickstart-image:tag1
Digest: sha256:70c42...
Status: Image is up to date for gcr.io/[PROJECT-ID]/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

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

What's next