Nginx/Flask/Redis Sample Compose
This commit is contained in:
parent
84109dcddc
commit
99d423e7dd
23
nginx-flask-redis/docker-compose.yml
Normal file
23
nginx-flask-redis/docker-compose.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
version: '3.6'
|
||||||
|
|
||||||
|
services:
|
||||||
|
redis:
|
||||||
|
image: redislabs/redis
|
||||||
|
ports:
|
||||||
|
- '6379:6379'
|
||||||
|
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: ./web/
|
||||||
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
|
links:
|
||||||
|
- redis
|
||||||
|
|
||||||
|
nginx:
|
||||||
|
restart: always
|
||||||
|
build: ./nginx/
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
links:
|
||||||
|
- web
|
3
nginx-flask-redis/nginx/Dockerfile
Normal file
3
nginx-flask-redis/nginx/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM nginx:alpine
|
||||||
|
RUN rm /etc/nginx/conf.d/default.conf
|
||||||
|
ADD sites-enabled/app /etc/nginx/conf.d/default.conf
|
14
nginx-flask-redis/nginx/sites-enabled/app
Normal file
14
nginx-flask-redis/nginx/sites-enabled/app
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
server {
|
||||||
|
|
||||||
|
listen 80;
|
||||||
|
server_name 0.0.0.0;
|
||||||
|
charset utf-8;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://web:8000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
nginx-flask-redis/web/Dockerfile
Normal file
7
nginx-flask-redis/web/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
FROM python
|
||||||
|
|
||||||
|
COPY . /
|
||||||
|
|
||||||
|
RUN pip install -r requirements.txt && pip install gunicorn
|
||||||
|
RUN /usr/local/bin/python -m pip install --upgrade pip
|
||||||
|
ENTRYPOINT ["/start.sh"]
|
16
nginx-flask-redis/web/app/app.py
Normal file
16
nginx-flask-redis/web/app/app.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
import os
|
||||||
|
import socket
|
||||||
|
|
||||||
|
from flask import Flask
|
||||||
|
from redis import Redis
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
redis = Redis(host=os.environ.get('REDIS_HOST', 'redis'), port=6379)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def hello():
|
||||||
|
redis.incr('hits')
|
||||||
|
return 'Hi Docker! You have seen %s times and your system is %s.\n' % (redis.get('hits'),socket.gethostname())
|
16
nginx-flask-redis/web/app/config.py
Normal file
16
nginx-flask-redis/web/app/config.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import multiprocessing
|
||||||
|
import os
|
||||||
|
|
||||||
|
from distutils.util import strtobool
|
||||||
|
|
||||||
|
|
||||||
|
bind = os.getenv('WEB_BIND', '0.0.0.0:8000')
|
||||||
|
accesslog = '-'
|
||||||
|
access_log_format = "%(h)s %(l)s %(u)s %(t)s '%(r)s' %(s)s %(b)s '%(f)s' '%(a)s' in %(D)sµs" # noqa: E501
|
||||||
|
|
||||||
|
workers = int(os.getenv('WEB_CONCURRENCY', multiprocessing.cpu_count() * 2))
|
||||||
|
threads = int(os.getenv('PYTHON_MAX_THREADS', 1))
|
||||||
|
|
||||||
|
reload = bool(strtobool(os.getenv('WEB_RELOAD', 'false')))
|
3
nginx-flask-redis/web/requirements.txt
Normal file
3
nginx-flask-redis/web/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Flask==2.0.3
|
||||||
|
redis==4.1.4
|
||||||
|
|
3
nginx-flask-redis/web/start.sh
Normal file
3
nginx-flask-redis/web/start.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
gunicorn -c app/config.py app.app:app
|
Loading…
Reference in New Issue
Block a user