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
gcloud command-line tool; alternatively, you can use the
quickstart with curl.
Before you beginTake the following steps to enable the Container Builder API:
- Enable the Container Builder API in the Google Cloud Platform Console.
- Create or select a project.
- Click Continue to enable the API and any related services. This step may take a few minutes.
- Enable billing for your project.
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:
Authorize access to Cloud resources (if you are using Cloud Shell you can skip this step):
gcloud auth login
Set the active project for the
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
resource in the Container Builder API. See
Build Requests for more
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'
Save the file as
Send the build request
Send the build request to Container Builder using the
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.
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.
To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:
- Go to the Cloud Platform Console.
- Click the trash can icon next to the project you want to shut down. This schedules the project for deletion.