がじぇ

お金と家電とプログラミングのブログ

Python 3.7とgoogle cloud sdkが入ったDockerコンテナ

おはようございます。

がじぇったー (@hackmylife7) | Twitter


です。


掲題の通りですがPython+Google Cloud SDKがはいったコンテナを作る必要があってDockerfileをつくったのでその共有です。



Dockerfile

こんな感じに描きました。

# Use the official Python image.
# https://hub.docker.com/_/python
FROM python:3.7

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

# Change Timezone to JP
RUN cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

# Install production dependencies.
RUN pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib pandas \
    && curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /app/google-cloud-sdk.tar.gz  \
    && mkdir -p /usr/local/gcloud \
    && tar -C /usr/local/gcloud -xvf /app/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

CMD ["python" "main.py"]

build したあとrunをすれば、gcloudコマンドが出てくると思います。

$ docker build -t  container_name .
$ docker run -it container_name