Build a Docker Image on GCP

Building Docker images from a Jupyter notebook and submitting them to Container Registry

If you’re using a Jupyter notebook in Kubeflow on Google Cloud Platform(GCP), you can submit Docker image builds toCloud Build. Cloud Build buildsthe Docker image and pushes it toGoogle Container Registry.

Building a Docker image

Run the following command in a Jupyter notebook cell to activate the attachedservice account:

  1. !gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}

Run thegcloud builds submit command to submit a build. The following example assumes that your Dockerfile is in the current directory:

  1. !gcloud builds submit --tag gcr.io/myproject/myimage:tag .

A bit about authentication

Kubeflow assigns the jupyter-notebook service account to the Jupyter notebookPods.The ${GOOGLE_APPLICATION_CREDENTIALS} environment variable is pre-configuredin the notebook. Its value is a path that points to a JSON file containing aKubernetes secret.The secret contains the credentials needed to authenticate as the notebookservice account within the cluster. To see the value of the environmentvariable, enter the following command in a notebook cell:

  1. !echo ${GOOGLE_APPLICATION_CREDENTIALS}

You should see a response similar to this:

  1. /secrets/gcp-service-account-credentials/user-gcp-sa.json

Next steps

Feedback

Was this page helpful?

Glad to hear it! Please tell us how we can improve.

Sorry to hear that. Please tell us how we can improve.

Last modified 19.04.2019: Refactored and significantly updated the Jupyter notebooks docs (#633) (4e1d8ab2)