p:: CLI, Docker

Installing the gcloud CLI

macOS

macOS 64-bit (arm64, Apple M1 silicon)

{
    cd ~
    wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-392.0.0-darwin-arm.tar.gz
    tar -xvzf google-cloud-cli-392.0.0-darwin-arm.tar.gz
 
    ./google-cloud-sdk/install.sh
}

Open a new terminal so that the changes take effect.

gcloud init

Installing the Cloud SDK Docker image

docker run --rm gcr.io/google.com/cloudsdktool/cloud-sdk:latest gcloud version
Google Cloud SDK 384.0.1
alpha 2022.05.04
app-engine-go 1.9.72
app-engine-java 1.9.96
app-engine-python 1.9.100
app-engine-python-extras 1.9.96
beta 2022.05.04
bigtable
bq 2.0.74
bundled-python3-unix 3.8.11
cbt 0.12.0
cloud-datastore-emulator 2.2.0
cloud-firestore-emulator 1.14.3
cloud-spanner-emulator 1.4.2
core 2022.05.04
datalab 20190610
gsutil 5.10
kpt 1.0.0-beta.13
local-extract 1.5.2
pubsub-emulator 0.6.0
  • Authenticate with the gcloud command-line tool by running:
docker run -ti \
    --name gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk \
    gcloud auth login --no-launch-browser

Once you’ve authenticated successfully, credentials are preserved in the volume of the gcloud-config container.

  • List compute instances using these credentials to verify by running the container with --volumes-from:
PROJECT_ID=adithya321
docker run --rm --volumes-from \
    gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk \
    gcloud compute instances list --project $PROJECT_ID
Listed 0 items.