Last active
August 2, 2018 12:39
-
-
Save hiroykam/b11b4f545b011f879b9d22e5d7a94a42 to your computer and use it in GitHub Desktop.
DockerでPython+uWSGI+Nginxの環境を作成 ref: https://qiita.com/hiroykam/items/748c3fab31c616994db9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| server { | |
| listen 80 default; | |
| server_name _; | |
| location / { | |
| include uwsgi_params; | |
| uwsgi_pass localhost:8080; | |
| } | |
| location = /favicon.ico { | |
| empty_gif; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "2" | |
| services: | |
| # nginx | |
| nginx-python: | |
| build: ./nginx-python | |
| ports: | |
| - "8080:80" | |
| volumes: | |
| - ./app/:/var/www/html/app/ | |
| environment: | |
| TZ: "Asia/Tokyo" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM centos:6.8 | |
| ADD ./conf/nginx.repo /etc/yum.repos.d/ | |
| # nginx & python | |
| RUN yum localinstall -y http://rpms.famillecollet.com/enterprise/remi-release-6.rpm | |
| RUN yum install -y https://centos6.iuscommunity.org/ius-release.rpm | |
| RUN yum install -y nginx-1.10.1 | |
| RUN yum install -y make gcc | |
| RUN yum install -y libxml2-devel | |
| RUN yum install -y python35u python35u-libs python35u-devel python35u-pip | |
| RUN yum clean all | |
| RUN ln -s /usr/bin/python3.5 /usr/bin/python3 | |
| RUN unlink /usr/bin/python | |
| RUN ln -s /usr/bin/python3 /usr/bin/python | |
| RUN ln -s /usr/bin/pip3.5 /usr/bin/pip | |
| RUN pip install uwsgi | |
| # setting nginx | |
| COPY conf/nginx.conf /etc/nginx/nginx.conf | |
| ADD conf/default.conf /etc/nginx/conf.d/default.conf | |
| RUN usermod -u 1000 nginx | |
| EXPOSE 80 | |
| ADD ./conf/start.sh /tmp/start.sh | |
| CMD /bin/sh /tmp/start.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker-compose build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker-compose up |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker ps -a | |
| CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
| 0be4855e99df dockerpython_nginx-python "/bin/sh -c '/bin/..." 2 hours ago Up 2 hours 0.0.0.0:8088->80/tcp dockerpython_nginx-python_1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker stop 0be4855e99df |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker start 0be4855e99df |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker restart 0be4855e99df |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker exec -it 0be4855e99df bash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $docker rm 0be4855e99df |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ touch docker_python/app/uwsgi.log | |
| $ touch docker_python/app/uwsgi.pid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docker-compose up --build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user nginx; | |
| worker_processes 1; | |
| error_log /var/log/nginx/error.log warn; | |
| pid /var/run/nginx.pid; | |
| events { | |
| worker_connections 1024; | |
| } | |
| http { | |
| include /etc/nginx/mime.types; | |
| default_type application/octet-stream; | |
| 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 off; | |
| #tcp_nopush on; | |
| keepalive_timeout 65; | |
| #gzip on; | |
| include /etc/nginx/conf.d/*.conf; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [nginx] | |
| name=nginx repo | |
| baseurl=http://nginx.org/packages/centos/6/$basearch/ | |
| gpgcheck=0 | |
| enabled=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| /etc/init.d/nginx start | |
| cd /var/www/html/app | |
| chmod -R 777 . | |
| uwsgi --ini uwsgi.ini |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [uwsgi] | |
| master = True | |
| socket = localhost:8080 | |
| wsgi-file = webapp.py | |
| stats = localhost:8181 | |
| logto = uwsgi.log | |
| pidfile = uwsgi.pid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def application(environ, start_response): | |
| start_response('200 OK', [('Content-Type','text/html')]) | |
| return [b"Hello World"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment