1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dockerfile: install gcloud CLI

Last updated at Posted at 2024-10-10

動機

Googleが公開しているimage google/cloud-sdkを最初にPULLすれば簡単なのだが、例えばPythonのバージョン依存などでpython:3.10-slimをbaseにしたいとき自分でgcloud CLIをインストールする必要性があった。

Dockerfile

できてしまえば簡単だが忘れると面倒なのでメモ。

FROM python:3.10-slim

RUN apt-get update && apt-get install -y \
  curl \
  apt-transport-https \
  ca-certificates \
  gnupg \
  sudo
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 | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg \
  && apt-get update -y \
  && apt-get install google-cloud-sdk -y

ENV CLOUDSDK_CORE_PROJECT=[your google cloud project]

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME

# Install production dependencies.
RUN pip install --break-system-packages --no-cache-dir -r requirements.txt
RUN chmod +x main.py

ENTRYPOINT ["python3", "main.py"]

Reference

インストールのcommandは以下のドキュメントを参照した:

Docker Tip: If installing the gcloud CLI inside a Docker image, use a single RUN step instead: ...

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?