How to install Google Cloud SDK in Docker image?

How can I create a Docker container with the Google Cloud Command / SDK command line tool ?

The script on url https://sdk.cloud.google.com seems to require user input, so it doesn't work in the docker file.

+33
source share
12 answers

Adding the following to my Docker file works.

# Downloading gcloud package RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz # Installing the package RUN mkdir -p /usr/local/gcloud \ && tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz \ && /usr/local/gcloud/google-cloud-sdk/install.sh # Adding the package path to local ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin 
+39
source

Use this single line layer in your Docker file:

 RUN curl -sSL https://sdk.cloud.google.com | bash 

Source: https://docs.docker.com/v1.8/installation/google/

+18
source

Do it with alpine:

  FROM alpine:3.6 RUN apk add --update \ python \ curl \ which \ bash RUN curl -sSL https://sdk.cloud.google.com | bash ENV PATH $PATH:/root/google-cloud-sdk/bin 
+14
source

Alternatively, you can use the docker image provided by Google, namely google/cloud-sdk . https://hub.docker.com/r/google/cloud-sdk/

+5
source
 RUN curl -sSL https://sdk.cloud.google.com > /tmp/gcl && bash /tmp/gcl --install-dir=~/gcloud --disable-prompts` 
+5
source

Dockerfile:

 FROM centos:7 RUN yum update -y && yum install -y \ curl \ which && \ yum clean all RUN curl -sSL https://sdk.cloud.google.com | bash ENV PATH $PATH:/root/google-cloud-sdk/bin 

Addition:

 docker build . -t google-cloud-sdk 

Then run gcloud :

 docker run --rm \ --volume $(pwd)/assets/root/.config:/root/.config \ google-cloud-sdk gcloud 

... or run gsutil :

 docker run --rm \ --volume $(pwd)/assets/root/.config:/root/.config \ google-cloud-sdk gsutil 

The local assets folder will contain the configuration.

+2
source

I used most of these examples in some form (thanks @KJoe), but I had to do a few more things to set everything up so that gcloud work in the environment. Note that it is preferable to limit the number of lines (this limits the layers that need to be pulled)

Here's a more complete Dockerfile example with gcloud configuring and extending the CircleCI image:

 FROM circleci/ruby:2.4.1-jessie-node-browsers # user is circleci in the FROM image, switch to root for system lib installation USER root ENV CCI /home/circleci ENV GTMP /tmp/gcloud-install ENV GSDK $CCI/google-cloud-sdk ENV PATH="${GSDK}/bin:${PATH}" # do all system lib installation in one-line to optimize layers RUN curl -sSL https://sdk.cloud.google.com > $GTMP && bash $GTMP --install-dir=$CCI --disable-prompts \ && rm -rf $GTMP \ && chmod +x $GSDK/bin/* \ \ && chown -Rf circleci:circleci $CCI # change back to the user in the FROM image USER circleci # setup gcloud specifics to your liking RUN gcloud config set core/disable_usage_reporting true \ && gcloud config set component_manager/disable_update_check true \ && gcloud components install alpha beta kubectl --quiet 
0
source

My use case was to generate a Google bearer token using a service account, so I wanted the gcloud container to install gcloud This is how my gcloud file looks like

 FROM google/cloud-sdk # Setting the default directory in container WORKDIR /usr/src/app # copies the app source code to the directory in container COPY . /usr/src/app CMD ["/bin/bash","/usr/src/app/token.sh"] 

If you need to check the container after its docker run --rm -it <container-build-id> bash -il but it is not running, use docker run --rm -it <container-build-id> bash -il and enter gcloud --version if it is installed correctly or not

0
source

This is a job for me.

 FROM php:7.2-fpm RUN apt-get update -y RUN apt-get install -y python && \ curl -sSL https://sdk.cloud.google.com | bash ENV PATH $PATH:/root/google-cloud-sdk/bin 
0
source

An example of using Debian as a base image:

 FROM debian:stretch RUN apt-get update && apt-get install -y apt-transport-https gnupg curl lsb-release RUN export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \ echo "cloud SDK repo: $CLOUD_SDK_REPO" && \ echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \ apt-get update -y && apt-get install google-cloud-sdk -y 
0
source

I got this while working with Ubuntu 18.04 using:

 RUN apt-get install -y curl && curl -sSL https://sdk.cloud.google.com | bash ENV PATH="$PATH:/root/google-cloud-sdk/bin" 
0
source
 apk upgrade --update-cache --available && \ apk add openssl && \ apk add curl python3 py-crcmod bash libc6-compat && \ rm -rf /var/cache/apk/* curl https://sdk.cloud.google.com | bash > /dev/null export PATH=$PATH:/root/google-cloud-sdk/bin gcloud components update kubectl 
0
source

Source: https://habr.com/ru/post/1212831/


All Articles