Quickstart for Google Container Registry

This quickstart demonstrates how to build a Docker image and push it to Google 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 Platform Console, go to the Manage resources page and select or create a new project.

    Go to the Manage resources page

  3. Enable billing for your project.

    Enable billing

  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}

    You may need to restart your system after adding yourself to the docker group.

  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.

Building the Docker image

At minimum, a Docker image consists of three files: a Dockerfile, a requirements.txt file, and your code.Dockerfile defines your image's environment, and requirements.txt defines your image's dependencies.

This quickstart shows you how to build a small Python web application which uses the Flask web framework to serve a web page. The web page displays the message "Hello, World!"

To prepare the Docker image, perform these steps:

  1. Create a directory to store your three Docker image files.

  2. In your Docker image directory, create three files: Dockerfile, requirements.txt, and app.py. See the examples below for what you'll need to put in the contents of each file:


# Import Python runtime and set up working directory
FROM python:2.7-slim
ADD . /app

# Install any necessary dependencies
RUN pip install -r requirements.txt

# Open port 80 for serving the webpage

# Run app.py when the container launches
CMD ["python", "app.py"]




from flask import Flask
import os
import socket

app = Flask(__name__)

def hello():
    html = "<h3>Hello, World!</h3>"
    return html

if __name__ == "__main__":
  app.run(host='', port=80)

To build the Docker image, run the following Docker command from the directory containing the image's files:

docker build -t quickstart-image .

You have now created a Docker image!

Tagging your image

Before you push your Docker image, you need to tag it with its registry name. Tagging your Docker image with a registry name configures the docker push command to push the image to a specific location.

The registry name format is below:



  • [HOSTNAME]is the gcr.io hostname
  • [PROJECT-ID] is your Google Cloud Platform Console project ID
  • [IMAGE] is your image's name

To tag your Docker image for Container Registry, run the following command:


For example:

docker tag quickstart-image gcr.io/my-project/quickstart-image

You are now ready to push your image to Container Registry!

Pushing your image

To push your Docker image to Container Registry, run the following command:

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

For example:

gcloud docker -- push gcr.io/my-project/quickstart-image

You can view images hosted by Container Registry via the Cloud Platform Console, or by visiting the image's registry name in your web browser: http://[HOSTNAME]/[PROJECT-ID]/[IMAGE].

Testing your image

To test that an instance of your image runs as expected, you can pull your image from Container Registry and run an instance from your system.

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

gcloud docker -- pull [HOSTNAME]/[PROJECT-ID]/[IMAGE]

You should see output similar to the following:

  latest: Pulling from [PROJECT-ID]/[IMAGE]
  Digest: sha256:70c42...
  Status: Image is up to date for [HOSTNAME]/[PROJECT-ID]/[IMAGE]

Run the gcloud container images list command to see your pulled images:


To run an instance of your image:

docker run -p 80:80 [HOSTNAME]/[PROJECT-ID]/[IMAGE]

If the output is similar to * Running on (Press CTRL+C to quit), your instance is running! To view the results, open your web browser to http://localhost:80.

Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

Delete your Docker image and Cloud Storage bucket

  1. To delete your Docker image, run the following command:

    gcloud container images delete [HOSTNAME]/[PROJECT-ID]/[IMAGE]
  2. Run the gsutil ls command to see your project's Cloud Storage buckets.

  3. To delete your Cloud Storage bucket:

    gsutil rb gs://[STORAGE-BUCKET]

    where gs://[STORAGE-BUCKET] is the full bucket name displayed by gsutil ls.

Delete your project

  1. Go to the Cloud Platform Console.
  2. Click the check box beside your project, then click Delete Project. This schedules the project for deletion.

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Container Registry