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
/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