2017-12-19 13 views
0

CentOS 7環境でFlaskアプリケーションを提供するために、uWSGIまたはGunicornとNginxを使ってDocker画像の例を見つけるためにインターネットを検索してきました。私が見つけた最も近いものはthisで、それはUbuntuベースです。どのように私はこのDockerfile代わりにUbuntuでのCentOSの7を使用するために再作成することができます:CentOSのFlaskアプリケーション用uWSGI/Gunicorn + Nginxのドッカー画像

FROM ubuntu:14.04 
MAINTAINER Phillip Bailey <[email protected]> 

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"] 
+0

なぜCentOSが必要ですか? –

+0

Stack Overflowは、プログラミングおよび開発に関する質問のサイトです。この質問は、プログラミングや開発に関するものではないので、話題にはならないようです。ヘルプセンターの[ここではどのトピックを参照できますか](http://stackoverflow.com/help/on-topic)を参照してください。おそらく、[スーパーユーザ](http://superuser.com/)や[Unix&Linux Stack Exchange](http://unix.stackexchange.com/)の方が良いかもしれません。 – jww

答えて

1

ここでは、最新のCentOSベース、nginxのとgunicornを持つ変異体です。 この設定は単なるスケッチに過ぎないことに注意してください。このような設定にはいくつかのセキュリティ上の問題があります(例えば、フラスコのアプリケーションはrootとして実行されます)が、私はそれがubuntuに基づいてセットアップの主な違いを概説していると思います。

Dockerfile:

FROM centos:latest 
MAINTAINER Deine Mudda<[email protected]> 

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のwackynessesの一部で、デフォルトのレポバージョンです):

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 
関連する問題