Docker 将Django部署到App Engine灵活环境-超时错误响应:[4]

Docker 将Django部署到App Engine灵活环境-超时错误响应:[4],docker,google-app-engine,google-cloud-platform,geodjango,Docker,Google App Engine,Google Cloud Platform,Geodjango,我正在尝试将我的应用程序部署到灵活的环境中。Docker映像构建得很好,但当我认为它试图使服务上线时,该过程失败。我的构建超时值设置为1200 我如何进一步询问此错误?我正在努力找到日志/GCP系统中的哪些地方,我可以找到卡住的确切流程。这似乎是一个完全不透明的错误,没有任何迹象表明到底出了什么问题。是不是应用程序中存在一些错误(在本地运行正常)?如果是这样的话,我希望它仍在部署中,但只是在我访问网站时显示错误 非常感谢您的帮助 错误: OperationError: Error Respons

我正在尝试将我的应用程序部署到灵活的环境中。Docker映像构建得很好,但当我认为它试图使服务上线时,该过程失败。我的构建超时值设置为1200

我如何进一步询问此错误?我正在努力找到日志/GCP系统中的哪些地方,我可以找到卡住的确切流程。这似乎是一个完全不透明的错误,没有任何迹象表明到底出了什么问题。是不是应用程序中存在一些错误(在本地运行正常)?如果是这样的话,我希望它仍在部署中,但只是在我访问网站时显示错误

非常感谢您的帮助

错误:

OperationError: Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.
ERROR: (gcloud.app.deploy) Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.
这是我的Dockerfile:

FROM gcr.io/google-appengine/python

RUN apt-get update && apt-get install software-properties-common -y
RUN add-apt-repository ppa:ubuntugis/ppa

RUN apt-get install -y gdal-bin


# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
# Use -p python3 or -p python3.7 to select python version. Default is version 2.
RUN virtualenv /env -p python3.7



# 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
COPY requirements.txt /tmp
WORKDIR /tmp
RUN pip install -r requirements.txt

# Add the application source code.
ADD . /

EXPOSE 8080
# Run a WSGI server to serve the application. gunicorn must be declared as
# a dependency in requirements.txt.
#CMD gunicorn -b :$PORT main:app
这是我的应用程序。yaml:

runtime: custom
env: flex

runtime_config:
  # You can also specify 2 for Python 2.7
  python_version: 3.7

我几乎可以肯定,这是由gunicorn超时引起的

要禁用gunicorn的超时行为,请将Dockerfile中的最后一个命令更改为:

CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 main:app --timeout 0
其中:
--worker 1--threads 8
表示一个worker进程和8个线程。 (如果不手动指定资源,默认值为1个CPU核心) 如果您决定使用更多的内核,那么相应地更改工作线程和线程,但这有点超出了这个问题的范围

重要的部分是
--timeout 0
,它基本上可以防止gunicorn超时

如果您仍然看到错误,那么有一个小的补充,将最有可能修复它。 启动gunicorn时,也要使用
--preload
标志。因此Dockerfile中的最后一个命令是:

CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 main:app --timeout 0 --preload
这将基本上确保在创建托管docker容器的实例时完成所有需要的导入和预处理。当您使用需要花费大量时间进行一次性预处理的应用程序时,这非常有用。 这样,一旦请求到来,所有内容都已加载并准备好为该请求提供服务

为了最大限度地发挥
--preload
的优势,您还需要将所有导入等移动到主应用程序的最开始,并避免在路由处理程序中调用导入

此外,在app.yaml和Dockerfile中都使用entrypoint命令也没有意义。在我看来,最好把它放在Dockerfile里

此外:


我会将
EXPOSE 8080
移动到FROM行之后的右侧,因为这将确保您的容器与外部世界有正确的连接。

您是否尝试增加app\u start\u timeout\u sec的值?(最大值为1800)。这将为您的应用程序启动和准备提供更宽的时间窗口。有关更多详细信息,请参阅。是的-不幸的是,它仍然失败。谢谢。你对
entrypoint
CMD
发表了评论,这正常吗?很好,但不幸没有什么区别:(尝试在app.yaml中指定healtcheck,并验证对healtcheck端点的调用是否给出了正确的响应(通常是200):