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-12-24Docker环境部署资料详解
- 2024-12-24Docker环境部署教程:新手入门详解
- 2024-12-24Docker环境部署项目实战教程
- 2024-12-24Docker环境部署学习:初学者指南
- 2024-12-24Docker环境部署入门:新手必读指南
- 2024-12-20Docker部署资料:新手入门教程
- 2024-12-19Docker部署实战:新手入门教程
- 2024-12-19Docker部署教程:新手入门详解
- 2024-12-09云原生周刊:在Docker上部署大语言模型
- 2024-12-05Docker教程:新手快速入门指南