[GCP][App Engine] Streamlit Web 应用部署 - 容器崩溃

Posted

技术标签:

【中文标题】[GCP][App Engine] Streamlit Web 应用部署 - 容器崩溃【英文标题】:[GCP][App Engine] Streamlit web app deployment - container crashed 【发布时间】:2020-10-31 13:47:19 【问题描述】:

我正在尝试在 Google App Engine 上部署使用 Streamlit 开发的网络应用程序。当部署过程接近完成时。我收到以下错误:

ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error! Code: APP_CONTAINER_CRASHED

  You can now view your Streamlit app in your browser.

  Network URL: http://172.17.0.6:8080
  External URL: http://34.67.15.189:8080

Killed

我无法理解此错误的根本原因。任何建议和/或帮助将不胜感激。

编辑:

我正在使用灵活的环境。 app.yaml 如下:

runtime: custom
env: flex

runtime_config:
  python_version: 3

manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 5
  disk_size_gb: 25

Dockerfile如下:

FROM python:3.7

# Copy local code to the container image.
WORKDIR /app
COPY requirements.txt ./requirements.txt

# Install dependencies.
RUN pip3 install -r requirements.txt

EXPOSE 8080

COPY . /app

# Run the web service on container startup.
CMD streamlit run --server.port 8080 --server.enableCORS false app.py

而且,要求是:

pandas==0.24.2
scikit_learn==0.23.1
streamlit==0.62.1

【问题讨论】:

您的应用程序在本地运行吗?共享您的应用程序的minimum reproducible example app.yaml 文件,如果您使用的是具有自定义运行时的 App Engine Flexible,请共享您正在使用的 Docker 映像。 @DanielOcando:感谢您的快速回复。我已经用app.yamlDockerfilerequirements.txt 编辑了这个问题。您能否将我重定向到任何参考或文档以在本地检查它(使用 Dockerfile 文件)? 首先,在本地测试应用,看看它是否能正常工作。我了解您的应用程序使用了 streamlit。所以你应该测试application itself works locally。之后您应该build the image locally 和run docker exec on the running container 来检查日志,看看是否有任何问题。 请注意,使用 streamlit 将要求您的 Dockerfile 具有附加配置,如 here 所述。 如果应用在本地运行,然后在容器级别运行,那么您可以考虑运行gcloud app deploy --verbosity=debug 以检查部署期间的其他问题。 【参考方案1】:

我使用了streamlit example app 和您的配置文件,我注意到您正在定义runtime_config,这不是必需的,因为您在 Dockerfile 中选择了通用 python docker 映像,这只适用于 App Engine 的 Python 映像。

有关自定义运行时的更多信息,请查看此document

对您的文件进行一些修改后,一切都在使用示例应用程序运行,请随意使用这些文件作为起点。

这是我的文件夹结构

./
├── app.py
├── app.yaml
├── Dockerfile
└── requirements.txt

这是我的 app.yaml

runtime: custom
env: flex

manual_scaling:
  instances: 1

resources:
  cpu: 4
  memory_gb: 5
  disk_size_gb: 25

这是我的 Dockerfile

FROM python:3.7

# Copy local code to the container image.
WORKDIR /app
COPY requirements.txt ./requirements.txt

# Install dependencies.
RUN pip3 install -r requirements.txt

EXPOSE 8080

COPY . /app

# Run the web service on container startup.
CMD streamlit run --server.port 8080 --server.enableCORS false /app/app.py

【讨论】:

谢谢 :) 我的应用有一个在执行期间需要访问的 csv 文件,我将它放在同一个文件夹中。没事吧? @Dhanya 如果您的 python 应用程序可以访问它,那很好 Google App Engine 上的 docker 文件大小是否有限制。我试图为另一个应用程序重新创建相同的内容。它由一个大小约为 1GB 的文件组成。

以上是关于[GCP][App Engine] Streamlit Web 应用部署 - 容器崩溃的主要内容,如果未能解决你的问题,请参考以下文章