python - 在Google App Engine上部署Flask和Tensorflow服务

标签 python docker google-app-engine gunicorn tensorflow-serving

我想将带有gunicorn和tensorflow服务的Flask API部署到Google App Engine(Flex)。我写了一个Dockerfile和startup.sh,但是部署失败。我将内存增加到6GB,并为gunicorn设置了2分钟的超时时间,但这无济于事。
Dockerfile运行成功,但是startup.sh不能同时启动gunicorn和tensorflow服务。有人可以指出sartup.sh出了什么问题吗?
Docker文件

FROM gcr.io/google-appengine/python

RUN virtualenv /env -p python3.7
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

RUN apt-get update
ADD app/ /app/
RUN pip install --upgrade pip
RUN pip install -r /app/requirements.txt

RUN echo "deb http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | tee /etc/apt/sources.list.d/tensorflow-serving.list && \
curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | apt-key add -
RUN apt-get update
RUN apt-get install -y tensorflow-model-server

RUN apt-get install -y nginx
COPY app/default /etc/nginx/sites-available/default

WORKDIR /root

RUN chmod -R a+r /var/www/html

COPY startup.sh /startup.sh
RUN chmod 744 /startup.sh
RUN cd /
CMD /startup.sh
启动.sh
#!/bin/bash
/etc/init.d/nginx start
cd /app && nohup gunicorn app:app --bind 127.0.0.1:8081 --workers 1 --timeout 120 &
nohup tensorflow_model_server \
  --rest_api_port=8501 \
  --model_name=bird_net \
  --model_base_path=/app/saved_model &
标准错误输出
$ gcloud app deploy
...
(ommited)
...
bc9f3e1065bb: Pushed
latest: digest: sha256:8dd67b5292199744a51d58c3cafb5ff17b87c4b39e35589c0d44e646dc1dd272 size: 5567
DONE
---------------------------------------------------------------------------------------------------------------------------------------------------------------

Updating service [default] (this may take several minutes)...failed.                                                                                          
ERROR: (gcloud.app.deploy) Error Response: [9] 
Application startup error! Code: APP_CONTAINER_CRASHED
 * Starting nginx nginx
   ...done.

最佳答案

我解决了Docker至少需要一个前台进程。

#!/bin/bash
set -m
/etc/init.d/nginx start
cd /app
gunicorn app:app --bind 127.0.0.1:8081 --workers 1 --timeout 120 &
tensorflow_model_server \
  --rest_api_port=8501 \
  --model_name=birdnet \
  --model_base_path=/app/saved_model
fg %1
引用文献
https://docs.docker.com/config/containers/multi-service_container/

关于python - 在Google App Engine上部署Flask和Tensorflow服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64098716/

相关文章:

python - 如何在 Python 中查找空列表的所有索引

python - 了解 Python 3.7 中类、namedtuple 和 __slots__ 的大小

docker - 如何从另一个容器连接到独立的 selenium-firefox 容器

c# - 在 docker 容器异常 : Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl' 中运行的身份服务器 4

google-app-engine - App Engine - 带投影的 NDB 查询需要子属性吗?

java - 如何在 Google App Engine 上重新部署应用程序?

google-app-engine - 在 Travis-CI 上运行 Google App Engine 并使用 PhantomJS 进行测试

python - 是否可以运行 python 文件,编辑它,然后在第二个终端中运行它

python - 如何使用 selenium 执行网页上的所有 javascript 内容以在完全加载的网页上查找和发送登录表单信息

docker - 构建 Docker 镜像但不保存?