yt coffee

Study hard, play harder.

How to Use Google Cloud SDK Using Docker

  • 2019-01-17 05:43
  • #GCP

The one thing you can't avoid when using GCP is the Google Could SDK. However, I don't want to install a tool on the local machine's system globals if possible.

So I decided to use google/cloud-sdk, the official Google Docker image, in my local environment.

Prepare Docker Images

There are three types of tags for google/cloud-sdk:

  • latest, VERSION: Large image with additional components pre-installed, Debian-based.
  • slim, VERSION-slim: Smaller image with no components pre-installed, Debian-based.
  • alpine, VERSION-alpine: Smallest image with no additional components installed, Alpine-based.

I wanted to use Google AppEngine & AppEngine components is included in the default components, so I decided to use alpine:

docker pull google/cloud-sdk:alpine
docker run -it --rm google/cloud-sdk:alpine gcloud version
# Google Cloud SDK 229.0.0
# bq 2.0.39
# core 2019.01.04
# gsutil 4.35

Auth

Specify --name option to persist auth information:

docker run -it --name gcloud-config \
    google/cloud-sdk:alpine gcloud auth login

Copy and paste the displayed URL into the browser and follow the instructions, and finally copy and paste the verification code displayed on the screen into the terminal.

Use SDK

Use --volumes-from gcloud-config to mount the volume containing the auth information:

docker run --rm --volumes-from gcloud-config \
    google/cloud-sdk:alpine gcloud config list

References