Installing the Google Cloud CLI Docker image

The Google Cloud CLI Docker image lets you pull a specific version of gcloud CLI as a Docker image from Artifact Registry and quickly execute Google Cloud CLI commands in an isolated, correctly configured container.

The Google Cloud CLI Docker image is the gcloud CLI installed on top of a Debian or Alpine image. The Docker image is hosted on Artifact Registry with the following repository name: gcr.io/google.com/cloudsdktool/google-cloud-cli. The images are also available using the us.gcr.io, eu.gcr.io, and asia.gcr.io repositories.

Docker image options

There are five Google Cloud CLI Docker images: latest, slim, emulators, debian_component_based, and alpine. You can specify your preference by using the appropriate tag after the host repository name:

  • :latest, :VERSION: Large (Debian-based) image with additional components pre-installed.
  • :slim, :VERSION-slim: Smaller (Debian-based) image with no components pre-installed.
  • :emulators, :VERSION-emulators: Smaller (Debian-based) image with emulator components pre-installed.
  • :alpine, :VERSION-alpine: Smallest (Alpine-based) image with no additional components installed. This image supports linux/arm.
  • :debian_component_based, :VERSION-debian_component_based: Debian-based with all components. As opposed to :latest which used deb packages, this image uses the component manager to install components. This image supports linux/arm.

Installing a specified Docker image

  1. To use the image of the latest Google Cloud CLI release, gcr.io/google.com/cloudsdktool/google-cloud-cli:latest, pull it from Artifact Registry by running the following command:

    docker pull gcr.io/google.com/cloudsdktool/google-cloud-cli:latest
    
  2. If you've pulled the latest version, verify the installation by running:

    docker run --rm gcr.io/google.com/cloudsdktool/google-cloud-cli:latest gcloud version
    

    If you pulled a specific version, verify the installation by running a command similar to the following sample:

    docker run --rm gcr.io/google.com/cloudsdktool/google-cloud-cli:<release_version> gcloud version
    
  3. Authenticate with the Google Cloud CLI by running:

    docker run -ti --name gcloud-config gcr.io/google.com/cloudsdktool/google-cloud-cli gcloud auth login
    

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

  4. List compute instances using these credentials to verify by running the container with --volumes-from:

    docker run --rm --volumes-from gcloud-config gcr.io/google.com/cloudsdktool/google-cloud-cli gcloud compute instances list --project your_project
    

Installing additional components

By default, the latest images (gcr.io/google.com/cloudsdktool/google-cloud-cli:latest and gcr.io/google.com/cloudsdktool/google-cloud-cli:VERSION) have all the Google Cloud CLI components installed.

The gcr.io/google.com/cloudsdktool/google-cloud-cli:slim, gcr.io/google.com/cloudsdktool/google-cloud-cli:emulators and gcr.io/google.com/cloudsdktool/google-cloud-cli:alpine images, however, don't come with additional components pre-installed.

To install additional components for Alpine-based images, create a Dockerfile that uses the Google Cloud CLI image as the base image. For example, to add kubectl and app-engine-java components, create a Dockerfile to look like the following:

FROM gcr.io/google.com/cloudsdktool/google-cloud-cli:alpine
RUN apk --update-cache add openjdk7-jre
RUN gcloud components install app-engine-java kubectl

If openjdk7-jre does not work, try openjdk8-jre.

Once done, run the following command:

docker build -t my-cloud-sdk-docker:alpine .

Installing specific versions of Google Cloud CLI

To install specific Google Cloud CLI versions, specify your preferred gcloud CLI version when running the docker build command:

docker build -t my-cloud-sdk-docker:alpine --build-arg CLOUD_SDK_VERSION=<release_version> .

Check the latest Google Cloud CLI version and all previous Google Cloud CLI versions.