Docker + Flask + gunicorn + nginx + supervisord 部署服务
2021/10/26 7:14:23
本文主要是介绍Docker + Flask + gunicorn + nginx + supervisord 部署服务,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Dockerfile
FROM registry.cn-hangzhou.aliyuncs.com/hzmodi/python3.8:v2 RUN sed -i "s@/archive.ubuntu.com/@/mirrors.163.com/@g" /etc/apt/sources.list \ && rm -rf /var/lib/apt/lists/* \ && apt-get update --fix-missing -o Acquire::http::No-Cache=True RUN apt install -y nginx supervisor pngquant RUN pip install gunicorn # flask application RUN mkdir /root/compression WORKDIR /root/compression COPY app.py /root/compression/ COPY requirements.txt /root/compression/ RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ # nginx RUN rm /etc/nginx/sites-enabled/default COPY flask.conf /etc/nginx/sites-available/ RUN ln -s /etc/nginx/sites-available/flask.conf /etc/nginx/sites-enabled/flask.conf RUN echo "daemon off;" >> /etc/nginx/nginx.conf # supervisord RUN mkdir -p /var/log/supervisor COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY gunicorn.conf /etc/supervisor/conf.d/gunicorn.conf # run CMD ["/usr/bin/supervisord"]
flask app.py
from flask import Flask, request app = Flask(__name__) # app.config['FLASK_ENV'] = 'development' @app.route('/', methods=['GET']) def index(): return 'hello world' if __name__ == '__main__': app.run(host='0.0.0.0')
gunicorn.conf
[program:gunicorn] command=gunicorn --workers=2 app:app -b 0.0.0.0:4396 directory=/root/compression/
nginx.conf
server { listen 80; location / { proxy_pass http://127.0.0.1:4396; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
supervisord.conf
[supervisord] nodaemon=true [program:nginx] command=/usr/sbin/nginx
这篇关于Docker + Flask + gunicorn + nginx + supervisord 部署服务的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14Docker端口:你真的公开了哪些东西?
- 2024-11-14用DOCKER在家里的实验室里搞些酷炫的玩意儿
- 2024-11-05掌握Docker:高效安全的十大最佳实践
- 2024-11-05在 Docker Compose 中怎么设置端口映射-icode9专业技术文章分享
- 2024-11-05在 Docker Compose 中怎么设置环境变量-icode9专业技术文章分享
- 2024-11-04Docker环境部署项目实战:新手入门教程
- 2024-11-04Docker环境部署资料:新手入门教程
- 2024-11-01Docker环境部署教程:新手入门指南
- 2024-11-01超越Docker:苹果芯片上的模拟、编排和虚拟化方案讲解
- 2024-11-01Docker环境部署:新手入门教程