Skip to content
18 changes: 18 additions & 0 deletions docker/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.6-alpine3.8
ARG VERSION=v0.7.0

ENV PYTHONUNBUFFERED 1

RUN apk add --no-cache shadow
RUN useradd --user-group --create-home --home-dir /flask --shell /bin/false flask

RUN apk add --no-cache linux-headers make gcc musl-dev libxml2-dev libxslt-dev libffi-dev postgresql-dev git

RUN pip install --upgrade pip && pip install --no-cache-dir -e git+https://github.com/briancappello/flask-unchained.git@${VERSION}#egg=flask-unchained

WORKDIR /flask/src

USER flask

CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"]
EXPOSE 5000
17 changes: 17 additions & 0 deletions docker/stretch.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.6-stretch
ARG VERSION=v0.7.0

ENV PYTHONUNBUFFERED 1

RUN useradd --user-group --create-home --home-dir /flask --shell /bin/false flask

RUN apt-get update && apt-get install -y build-essential libxml2-dev libxslt-dev libffi-dev libpq-dev git

RUN pip install --upgrade pip && pip install --no-cache-dir -e git+https://github.com/briancappello/flask-unchained.git@${VERSION}#egg=flask-unchained

WORKDIR /flask/src

USER flask

CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"]
EXPOSE 5000
89 changes: 89 additions & 0 deletions docs/tutorial/docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Docker Container
--------------------

Running a flask app in a docker container is a comfortable way to avoid dependency installation.

Build Container
^^^^^^^^^^^^^^^

Change into flask-unchained source folder. Then run docker build command:

.. code:: bash

docker build -t briancappello/flask-unchained .

The container will be built and tagged with the name briancappello/flask-unchained.

Run Container
^^^^^^^^^^^^^

Change into your project folder created with 'flask new project PROJECT'.
Then run a container mounting your project's folder:

.. code:: bash

docker run -d --name PROJECT -p 5000:5000 -v "$(pwd)":/flask/src briancappello/flask-unchained

Your app runs now on localhost:5000.

Build Custom Container
^^^^^^^^^^^^^^^^^^^^^^

If you want dockerize your project you can create a Dockerfile in your project's folder.

.. code:: docker

# Dockerfile

FROM briancappello/flask-unchained
COPY . .
RUN pip install -r requirements-dev.txt && pip install -r requirements.txt

Then you can build and run your custom container as described above.

.. code:: bash

docker build -t PROJECT .
docker run -d --name PROJECT -p 5000:5000 -v "$(pwd)":/flask/src PROJECT

Docker Compose
^^^^^^^^^^^^^^

Docker Compose is a tool to configure containers, mountpoints and ports.
A simple compose file for an flask-unchained project is following:

.. code:: yaml

# docker-compose.yml

version: '3'
services:
postgres:
image: postgres:11.1-alpine

redis:
image: redis:5.0-alpine
command: redis-server
expose:
- 6379

app:
build:
context: .
dockerfile: Dockerfile
links:
- postgres
- redis
environment:
- FLASK_DATABASE_HOST=postgres
- FLASK_REDIS_HOST=redis
command: flask run --host 0.0.0.0 --port 5000
ports:
- 5000:5000
volumes:
- .:/flask/src

This file in project's folder and a simple command 'docker-compose up' starts
the app.
In this example next to the app container, one for postgres database and one for redis are started too.
They are available through their hostnames postgres and redis within the app container.
1 change: 1 addition & 0 deletions docs/tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Tutorial
session
security
building_the_portfolio
docker

This tutorial will walk you through creating a basic portfolio application for monitoring your investments. Users will be able to register, log in, create portfolios and manage the stocks in them. You will be able to package and install the application on other computers.

Expand Down