簡體   English   中英

帶有uWSGI / Gunicorn + Nginx的Docker映像,用於CentOS中的Flask應用程序

[英]Docker Image with uWSGI/Gunicorn + Nginx for Flask apps in CentOS

我一直在互聯網上搜索使用uWSGI或Gunicorn和Nginx在CentOS 7環境中提供Flask應用程序的Docker映像的任何示例。 我發現的最接近的是 ,它基於Ubuntu。 如何重新編寫此Dockerfile以使用CentOS 7而非Ubuntu:

FROM ubuntu:14.04
MAINTAINER Phillip Bailey <phillip@bailey.st>

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get install -y \
    python-pip python-dev uwsgi-plugin-python \
    nginx supervisor
COPY nginx/flask.conf /etc/nginx/sites-available/
COPY supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY app /var/www/app

RUN mkdir -p /var/log/nginx/app /var/log/uwsgi/app /var/log/supervisor \
    && rm /etc/nginx/sites-enabled/default \
    && ln -s /etc/nginx/sites-available/flask.conf /etc/nginx/sites-enabled/flask.conf \
    && echo "daemon off;" >> /etc/nginx/nginx.conf \
    &&  pip install -r /var/www/app/requirements.txt \
    && chown -R www-data:www-data /var/www/app \
    && chown -R www-data:www-data /var/log

CMD ["/usr/bin/supervisord"]

這是具有最新centos基礎,nginx和gunicorn的變體。 請注意,此配置僅是草圖。 這樣的設置存在幾個安全問題(例如,flask應用程序以root身份運行),但我認為它概述了基於ubuntu進行設置的主要區別。

Dockerfile:

FROM centos:latest
MAINTAINER Deine Mudda<deine@mudda.co.uk>

RUN yum -y update && yum -y install python-setuptools epel-release
RUN yum -y install nginx && \
    easy_install pip supervisor && \
    echo_supervisord_conf > /etc/supervisord.conf
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/flask.conf /etc/nginx/conf.d/
COPY supervisor/supervisord.conf /tmp/supervisord.conf
RUN cat /tmp/supervisord.conf >> /etc/supervisord.conf && \
    rm /tmp/supervisord.conf
COPY app /app
RUN pip install -r /app/requirements.txt

CMD ["/usr/bin/supervisord","-nc","/etc/supervisord.conf"]

nginx.conf(這是默認的回購版本,其中刪除了一些centos的怪癖):

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
daemon off;


events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;


}

flask.conf:

upstream flask {
    server 127.0.0.1:8080;
}

server {
    listen          80;
    location / {
            proxy_pass      http://flask;
    }

}

administratord.conf:

[program:flask]
directory=/app
command=gunicorn --bind 0.0.0.0:8080 app:app
autostart=true
autorestart=true

[program:nginx]
command=/usr/sbin/nginx
autostart=true
autorestart=true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM