我正在尝试构建自定义docker镜像,以便在我们在GAE上运行的django Web应用程序上运行测试和迁移。为此,我们需要使用Cloud SQL进行身份验证。这需要gcloud sdk + Cloud SQL代理的组合,但是,在docker build -t MY_IMAGE .
期间,我收到此错误/bin/sh: 1: gcloud: not found
。如何在构建过程中运行gcloud?
这是Dockerfile:
FROM gcr.io/google-appengine/python
LABEL python_version python3.5
# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
RUN virtualenv --no-download /env -p python3.5
# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
# Install Curl
RUN apt-get update; apt-get install curl
# Add GCloud SDK
RUN curl -o /tmp/google-cloud-sdk.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-155.0.0-linux-x86_64.tar.gz
RUN tar -xvf /tmp/google-cloud-sdk.tar.gz -C /tmp/
RUN /tmp/google-cloud-sdk/install.sh -q
RUN /bin/bash -c "source /tmp/google-cloud-sdk/path.bash.inc"
# Authenticate GCloud service account
RUN gcloud auth activate-service-account --key-file $credential
# Add and permission Cloud Proxy
RUN wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
RUN chmod +x cloud_sql_proxy
RUN mkdir /cloudsql; chmod 777 /cloudsql
# Run Cloud Proxy
RUN ./cloud_sql_proxy -dir=/cloudsql &
# Add the application source code.
ADD . /app
# Run migrations
RUN python manage.py migrate
# Run tests
# RUN python manage.py test
# Run a WSGI server to serve the application. gunicorn must be declared as
# a dependency in requirements.txt.
CMD gunicorn -b :$PORT main:app