Docker图像与uWSGI / Gunicorn + Nginx的Flask应用程序在CentOS

我一直在寻找互联网,find任何与uWSGI或Gunicorn和Nginx合作为CentOS 7环境中的Flask应用程序提供Docker镜像的示例。 我发现最近的是这个 ,它基于Ubuntu。 我如何重新编写Dockerfile来使用C​​entOS 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的变种。 请注意,此configuration仅仅是一个草图。 像这样的安装有几个安全问题(例如,烧瓶应用程序以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'wackyness的默认回购版本):

 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; } } 

supervisord.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 
Interesting Posts