Pushing and Pulling Images

This page describes how to push and pull images, which is two of the most common tasks done with Container Registry. To push a new image to Container Registry, you need to first tag it with the registry name, as described below.

To get up and running with Container Registry, see the quickstart.

For instructions on listing, tagging, and deleting images, see Managing Images.

Before you begin

Make sure that you have:

  1. Installed the Cloud SDK, which includes the gcloud command-line tool

  2. Installed Docker

  3. Configured Docker to use gcloud as a credential helper, or are using another authentication method. To use gcloud as the crediential helper, run the command:

    gcloud auth configure-docker
    

Pushing an image to a registry

To push any local image to Container Registry, you need to first tag it with the registry name and then push the image.

Tag the local image with the registry name

  1. Determine the registry name:

    1. Choose a hostname, which specifies the region of the registry's storage. This region is not your location, but the location where the images will be stored. For example, if you are in Australia, you may want to use the host in Asia.

      The four options are:

      • gcr.io hosts the images in the United States, but the location may change in the future
      • us.gcr.io hosts the image in the United States, in a separate storage bucket from images hosted by gcr.io
      • eu.gcr.io hosts the images in the European Union
      • asia.gcr.io hosts the images in Asia

      In the console, the images' hostname will be listed under Location.

    2. Choose an image name, which can be different from the image's name on your local machine.

    3. Combine the hostname, your Google Cloud Platform Console project ID, and image name:

      [HOSTNAME]/[PROJECT-ID]/[IMAGE]
      

      See Domain-scoped projects for how to work with projects IDs that include a domain.

  2. Tag the local image with the registry name by using the command:

    docker tag [SOURCE_IMAGE] [HOSTNAME]/[PROJECT-ID]/[IMAGE]
    

    where [SOURCE_IMAGE] is the local image name.

    This command names the image with the registry name and applies the tag latest. If you want to apply a different tag, then use the command:

    docker tag [SOURCE_IMAGE] [HOSTNAME]/[PROJECT-ID]/[IMAGE]:[TAG]
    

Push the tagged image to Container Registry

Push the tagged image to Container Registry by using the command:

docker push [HOSTNAME]/[PROJECT-ID]/[IMAGE]

This command pushes the image that has the tag latest. If you want to push an image that has a different tag, the use the command:

docker push [HOSTNAME]/[PROJECT-ID]/[IMAGE]:[TAG]

After pushing your image, you can:

  • Go to the GCP Console to view the registry and image.

  • Run gcloud container images list-tags to view the image's tag(s) and automatically-generated digest:

    gcloud container images list-tags [HOSTNAME]/[PROJECT-ID]/[IMAGE]
    

    The command's output is similar to the following:

    DIGEST        TAGS        TIMESTAMP
    44bde...      test        2017-..-..
    

Pulling images from the registry

To pull from Container Registry, use the command:

docker pull [HOSTNAME]/[PROJECT-ID]/[IMAGE]:[TAG]

or

docker pull [HOSTNAME]/[PROJECT-ID]/[IMAGE]@[IMAGE_DIGEST]

where:

  • [HOSTNAME] is listed under Location in the console. It's one of four options: gcr.io, us.gcr.io, eu.gcr.io, or asia.gcr.io.
  • [PROJECT-ID] is your Google Cloud Platform Console project ID). See Domain-scoped projects for how to work with projects IDs that include a domain.
  • [IMAGE] is the image's name in Container Registry.
  • [TAG] is the tag applied to the image. In a registry, tags are unique to an image.
  • [IMAGE_DIGEST] is the sha256 hash value of the image contents. In the console, click on the specific image to see its metadata. The digest is listed as the Image digest.

To get the pull command for a specific image:

  1. Click on the name of an image to go to the specific registry.

  2. In the registry, check the box next to the version of the image that you want to pull.

  3. Click SHOW PULL COMMAND on the top of the page.

  4. Copy the pull command, which identifies the image using either the tag or the digest.

What's next

Send feedback about...

Container Registry