Alpine based Flask and friends image
Alpine based docker image with Python3 including Flask, NGINX, uWSGI and Supervisord.
moppermonster/alpine-python-flask
FROM moppermonster/alpine-python-flask
COPY app.py /app.py
CMD ["/usr/bin/supervisord"]
An alternative to building your own container is mounting files over existing locations in the container.
Interesting files and their locations (in the container):
File | Description |
---|---|
/app.py | Main app, an example is provided with this repository |
/static/ | Static directory, by default NGINX is configured to deliver static content from this location |
/etc/nginx/nginx.conf | NGINX config file |
/etc/nginx/conf.d/flask-site-nginx.conf | NGINX config extension, static can be configured from here |
/etc/uwsgi/uwsgi.ini | UWSGI config file |
/etc/supervisord.conf | Supervisord config file |
Mounting files is considerably easier using docker-compose. This repository contains some examples.
FROM moppermonster/alpine-python-flask
# Install friends
RUN apk add --no-cache nginx uwsgi uwsgi-python3 supervisor
# Install Flask
COPY requirements.txt /tmp/requirements.txt
RUN pip3 install -r /tmp/requirements.txt
# Clean up
RUN rm /etc/nginx/conf.d/default.conf
RUN rm -r /root/.cache
# Config files
COPY nginx.conf /etc/nginx/
COPY flask-site-nginx.conf /etc/nginx/conf.d/
COPY uwsgi.ini /etc/uwsgi/
COPY supervisord.conf /etc/supervisord.conf
# Prepare static directory
RUN mkdir /static
# Copy default app.py
COPY app.py /app.py
CMD ["/usr/bin/supervisord"]
Simply use rebuild.sh
sh rebuild.sh
Default port: http://localhost:5678
docker build -t alpine-python-flask .
docker run -p 5678:80 alpine-python-flask