To install the Google Cloud SDK in a Docker image, you can create a Dockerfile that uses an appropriate base image and then adds the necessary steps to install the SDK.
Here’s an example of DockerFile using the ubuntu:20.04 base image:
# Use the official Ubuntu 20.04 image as the base
FROM ubuntu:20.04
# Set the environment variable for non-interactive installations
ENV DEBIAN_FRONTEND=noninteractive
# Install required dependencies
RUN apt-get update && \
apt-get install -y curl apt-transport-https ca-certificates gnupg lsb-release
# Add the Google Cloud SDK repository
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | \
tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \
gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
# Install the Google Cloud SDK
RUN apt-get update && \
apt-get install -y google-cloud-sdk
# Set the working directory
WORKDIR /root
# Start a new shell to use the installed SDK
CMD ["/bin/bash"]
First, save the contents above in a file named Dockerfile. Then, you can build the Docker image using the following command:
docker build -t my-gcloud-sdk-image .
Once the image is built, you can run a container using the new image with this command:
docker run -it --rm my-gcloud-sdk-image
This command will start an interactive shell inside the container, where you can access the gcloud command.
Remember to replace my-gcloud-sdk-image with the desired name for your Docker image.
That’s it.

Amit Doshi is a Cloud Engineer who has experienced more than 5 years in AWS, Azure, and Google Cloud. He is an IT professional responsible for designing, implementing, managing, and maintaining cloud computing infrastructure, applications, and services.