Skip to content

Instantly share code, notes, and snippets.

@davidcarboni
Last active October 12, 2020 15:00
Show Gist options
  • Save davidcarboni/9e645f847d78ebc676c44062b176e9c3 to your computer and use it in GitHub Desktop.
Save davidcarboni/9e645f847d78ebc676c44062b176e9c3 to your computer and use it in GitHub Desktop.
Flask in Docker - productionised with simplicity
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