Using the Google Cloud CLI on docker Last Modified: 2017-09-27
Using docker to run the Google Cloud command line interface
GCP Docker

Create a container with a configuration volume

docker run -ti --name gcloud-config google/cloud-sdk:latest gcloud auth login


Go to the following link in your browser:…

Enter verification code: _

Copy the address into your browser and log in with your google account. The sign in page should appear with a verification code.

Screenshot of the sign in web page.

Copy the verification code into the terminal. Once you authenticate successfully, credentials are preserved in the volume of the gcloud-config container. The gcloud-config container is used only for importing the volume in further invocations.

The cloud sdk images and documentation can be found on dockerhub:

Set project ID

docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk gcloud config set project <project id> (project id is in the format <project name>-<some number> e.g. myproject-181008)

Execute commands

e.g. to list compute instances, type

docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gcloud compute instances list