我想将带有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/