【发布时间】:2021-01-06 11:53:36
【问题描述】:
我使用flask/tensorflow 开发了一个小项目。它在应用服务器 - gunicorn 下运行。 我还必须将 nginx 包含到项目中以提供静态文件。没有 docker 应用程序运行良好。所有部分(gunicorn、nginx、flask)都按预期合作。现在是时候将这个项目移动到在线服务器了,我需要通过 docker 来完成。
Nginx 和 gunicorn->flask 应用通过 unix 套接字 进行通信。在我的本地主机环境中,我在应用程序根文件夹中使用了套接字 - myapp/app.sock,一切都很好。
现在的问题是我不太明白如何告诉 docker 内的 nginx 使用相同的套接字文件并告诉 gunicorn 听它。我收到以下错误:
上游:http://unix:/var/run/app.sock 在连接到上游时失败(没有这样的文件或目录)
尝试使用不同的套接字文件路径,但没有运气 - 同样的错误。
docker-compose 文件:
version: '3'
services:
nginx:
image: nginx:latest
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/remote-app:/etc/nginx/sites-enabled/remote-app
- /etc/nginx/proxy_params:/etc/nginx/proxy_params
ports:
- 8000:8000
build: .
command: gunicorn --bind unix:/var/run/app.sock wsgi:app --reload --workers 1 --timeout 60
environment:
- FLASK_APP=prediction_service.py
- FLASK_DEBUG=1
- PYTHONUNBUFFERED=True
restart: on-failure
main Dockerfile(对于主应用程序,它可以很好地构建应用程序,一切正常):
FROM python:3.8-slim
RUN pip install flask gunicorn flask_wtf boto3 tqdm
RUN pip install numpy==1.18.5
RUN pip install tensorflow==2.2.0 onnxruntime==1.4.0
COPY *.ipynb /temp/
COPY *.hdf5 /temp/
COPY *.onnx /temp/
COPY *.json /temp/
COPY *.py /temp/
WORKDIR /temp
nginx.conf 与默认值 99% 相同,只是增加了上传到 8M 的文件大小 proxy-params 只是用于发出 nginx 代理请求的配置参数的预设 并且 remote-app 是我的应用程序的配置(简单的一个):
server {
listen 8000;
server_name localhost;
location / {
include proxy_params;
proxy_pass htpp://unix:/var/run/app.sock; //**tried /temp/app.sock here same issue**
}
}
因此,如果我打开 localhost(即使没有端口 8000),我也可以获得 nginx 答案。如果我尝试打开 localhost:8000 我得到那个套接字错误(上面粘贴了强文本)。
【问题讨论】:
标签: docker ubuntu nginx flask gunicorn