Last active
October 12, 2020 15:00
-
-
Save davidcarboni/9e645f847d78ebc676c44062b176e9c3 to your computer and use it in GitHub Desktop.
Flask in Docker - productionised with simplicity
This file contains 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 python | |
# From the python:onbuild image | |
# For discussion of onbuild variant images see: https://hub.docker.com/_/python/ | |
WORKDIR /usr/src/app | |
COPY . /usr/src/app | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Install uWSGI | |
RUN pip install uwsgi | |
# Non-root user | |
# https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#user | |
RUN groupadd -r uwsgi && useradd -r -g uwsgi uwsgi | |
USER uwsgi | |
# Server | |
# | |
# We're using plain HTTP for simplicity but see also "uwsgi_pass" for Nginx: | |
# http://flask.pocoo.org/docs/0.12/deploying/uwsgi/ | |
# | |
# Inspired by: | |
# https://www.smartfile.com/blog/dockerizing-a-python-flask-application/ | |
# | |
# This assumes your main file is called "app.py" and your callable is called "app": | |
ENV PORT 5000 | |
CMD uwsgi --http 0.0.0.0:$PORT --module app:app --processes 1 --threads 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment