codekarim is just a bunch of reminders for fenuapps.com
version: '3' services: nginx: image: nginx restart: unless-stopped container_name: web-nginx volumes: - ./data/nginx:/etc/nginx/conf.d - ./data/html:/usr/share/nginx/html:ro ports: - "80:80" - "443:443" web-php: image: php:fpm-alpine container_name: web-php volumes: - ./data/docker-web/www:/script:ro flask: build: ./data/flask container_name: flask restart: always environment: - APP_NAME=MyFlaskApp - FLASK_APP=run.py - FLASK_ENV=development - FLASK_DEBUG=1 expose: - 8080 volumes: - ./data/flask:/app volumes: data:
/data/nginx/app.conf
upstream flask_webapp { server flask:5000; } server { listen 80; server_name kdzeta .fr www. kdzeta. fr; server_tokens off; index index.html; location / { root /usr/share/nginx/html; index index.html index.htm; } location ~ \.php$ { root /usr/share/nginx/html; include fastcgi_params; fastcgi_pass web-php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /script$fastcgi_script_name; } location /py { include uwsgi_params; uwsgi_pass flask:8080; } }
/data/flask/run.py
from app import app if __name__ == "__main__": app.run()
/data/flask/app.ini
[uwsgi] wsgi-file = run.py callable = app socket = :8080 processes = 4 threads = 2 master = true chmod-socket = 660 vacuum = true die-on-term = true
/data/flask/Dockerfile
# Use the Python3.7.2 image FROM python:3.7.2-stretch # Set the working directory to /app WORKDIR /app # Copy the current directory contents into the container at /app ADD . /app # Install the dependencies #RUN pip install -r requirements.txt RUN pip install flask uwsgi #VOLUME /app # run the command to start uWSGI CMD ["uwsgi", "app.ini"]
/data/flask/app/__init__.py
from flask import Flask app = Flask(__name__) from app import views
/data/flask/app/views.py
from app import app import os @app.route("/py") def index(): # Use os.getenv("key") to get environment variables app_name = os.getenv("APP_NAME") if app_name: return f"Hello from python {app_name} running in a Docker container behind Nginx!" return "Hello from Flask"
/data/docker-web/www/index.php