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

你可能感兴趣的:(python,Web,nginx,flask,docker,nginx,gunicorn,python)