Quickstart with the gcloud command-line tool

This quickstart shows how to use the Google Cloud Container Builder API to package a simple Node.js application as a Docker container. This quickstart uses the gcloud command-line tool; alternatively, you can use the quickstart with curl.

Before you begin

Take the following steps to enable the Container Builder API:

  1. Enable the Container Builder API in the Google Cloud Platform Console.
  2. Create or select a project.
  3. Click Continue to enable the API and any related services. This step may take a few minutes.
  4. Enable billing for your project.

    Enable billing

For this tutorial, you can use Cloud Shell or any other environment where the Google Cloud SDK is installed.

Log in to Google Cloud

If you are not using Cloud Shell, make sure to authorize access to Cloud resources using the following at a command prompt before you perform the tutorial steps:

  1. Authorize access to Cloud resources (if you are using Cloud Shell you can skip this step):

    gcloud auth login
    
  2. Set the active project for the gcloud command-line tool:

    gcloud config set project PROJECT_ID
    

    To see the IDs for all of your projects:

    gcloud projects list
    

Create a build request

The build request is a YAML document containing instructions that Container Builder needs to create the container image. Build requests are modeled using the Build resource in the Container Builder API. See Build Requests for more information.

  1. Create the build request by pasting the following code into a text file:

    steps:
    - name: 'gcr.io/cloud-builders/docker'
      args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/cb-demo-img', '.' ]
    images:
    - 'gcr.io/$PROJECT_ID/cb-demo-img'
    
  2. Save the file as cloudbuild.yaml.

Send the build request

Send the build request to Container Builder using the gcloud command-line tool:

gcloud container builds submit --config cloudbuild.yaml \
  gs://container-builder-examples/node-docker-example.tar.gz

As the build executes, its output is streamed to your terminal. When it finishes, you'll see something like:

DONE
---------------------------------------------------------------------------------
ID                                    CREATE_TIME                DURATION STATUS
$BUILD_ID                             2016-09-28T13:46:29+00:00  1M56S    SUCCESS

where $BUILD_ID is the generated unique identifier for your build.

Review build details

To see the details of the build that was executed, use:

gcloud container builds describe $BUILD_ID

Find the container image

When the status of your build is SUCCESS, you can find your container image in Google Container Registry.

List builds

To list all builds for your project:

gcloud container builds list

View build logs

To view build logs, open Cloud Logging in the Google Cloud Platform Console and select Container Builder > Build ID.

For more information, see Google Cloud Logging.

Clean up

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

  1. Go to the Cloud Platform Console.
  2. Click the trash can icon next to the project you want to shut down. This schedules the project for deletion.

What's next

Here are some topics to help you to continue learning about Google Container Builder.

Send feedback about...

Cloud Container Builder Documentation