Quickstart with a Dockerfile

This quickstart explains how to use the Container Builder API with the gcloud command-line tool to build a Docker image using your own application code and Dockerfile, and push it to Container Registry.

See Docker's Get Started documentation to learn how to prepare an application for Docker.

You can also complete Quickstart with gcloud command-line tool and Quickstart with curl.

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 Projects page and select or create a new project.

    Go to the Projects page

  3. Enable billing for your project.

    Enable billing

  4. Enable the Container Builder API.

    Enable the API

  5. Install and initialize the Cloud SDK.

Log in to Google Cloud

  1. Authorize gcloud to access your project:

    gcloud auth login
    
  2. Configure your project for gcloud, where [PROJECT-ID] is your Cloud Platform project ID:

    gcloud config set project [PROJECT_ID]
    

    If you don't know your project ID, run the following command:

    gcloud projects list
    

Submit a build using your Dockerfile

Your Dockerfile contains all of the instructions needed to build the Docker image.

To submit a build request using your Dockerfile, run the following command from the directory containing your application code, Dockerfile, and any other assets:

gcloud container builds submit --tag gcr.io/[PROJECT-ID]/[IMAGE] .

where

  • [PROJECT-ID] is your Cloud Platform project ID
  • [IMAGE] is the image to be built

The full name of the image to be built is gcr.io/[PROJECT-ID]/[IMAGE]. Images pushed to Container Registry use the registry name format.

The gcloud container builds submit command:

  • compresses your application code, Dockerfile, and any other assets;
  • uploads the files to a Cloud Storage bucket;
  • initiates a build using the uploaded files as input;
  • tags the image using the provided name; and
  • pushes the built image to Container Registry.

The build might take several minutes to complete. As the build progresses, its output is displayed in your shell or terminal window. When the build is complete, you should see output similar to the following:

DONE
---------------------------------------------------------------------------------
ID                                    CREATE_TIME                DURATION STATUS
$BUILD_ID                             2016-10-28T15:21:18+00:00  1M12S    SUCCESS

where $BUILD_ID is your build's unique identifier.

About build requests

Generally, build requests are JSON or YAML documents which instruct Container Builder to perform tasks, and to package, build, and push Docker images, based on your specifications.

Build requests are composed of build steps, which are Docker containers that execute code on your behalf. Calling build steps is analogous to calling scripts or shell commands.

In this case, since your Dockerfile contains the same instructions, there is no need to write a custom build request file.

View build details and the build logs

To view the details about your build and view its logs, visit the following URL:

https://console.cloud.google.com/gcr/builds/[BUILD-ID]?project=[PROJECT-ID]

where

  • [BUILD-ID] is your build's unique identifier
  • [PROJECT-ID] is your Cloud Platform project ID

The URL opens Container Registry's build history menu in your Cloud Platform project.

Locate your Docker image

When you build a Docker image using Container Builder, your resulting image is stored in Container Registry, a private repository for Docker images.

To locate your built image, run the following command:

gcloud container images list

list displays all images stored in Container Registry.

You can also:

Clean up

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

Delete your Docker image

To delete your Docker image, run the following command:

gcloud container images delete gcr.io/[YOUR-PROJECT-ID]/[IMAGE]

where [HOSTNAME]/[YOUR-PROJECT-ID]/[IMAGE] is your image's registry name.

If you don't know your image's registry name, run the following command:

gcloud container images list

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...

Cloud Container Builder