# quaintitative

I write about my quantitative explorations in visualisation, data science, machine and deep learning here, as well as other random musings.

For more about me and my other interests, visit playgrd or socials below

## Setting Up a Data Lab Environment - Part 6 - Serve a Flask

Adding Flask to the mix isn’t strictly required for this. But I think it’s great to be able to

• do the analysis;
• save the data to either the Postgres or Mongo database; and
• serve the analysis from a Flask server

I explained how to set up a Flask server in a previous post. Here, we show how to use Docker to do the same.

flaskapp:
ports:
- "80:80"
volumes:
- ./data:/app/data
environment:


We build an image from Dockerfile in the folder ‘docker/flask’ (which I will go through next); connect the container’s port 80 to port 80 in the outside world, map the volumes, and then set the variables and commands needed to get Flask up and running.

Next, we create a folder for flask in the docker folder that we had created previously. Within it, we create an app folder, and a Dockerfile.

In the Dockerfile, we pull a Docker image, and then install some libraries and copy the Flask app files from the local machine to the container’s app folder.

FROM tiangolo/uwsgi-nginx-flask:python3.6

RUN pip install pymongo
RUN pip install psycopg2
RUN pip install tweepy

COPY ./app /app


And that’s it. You can just adapt the files in the app folder I provided. It goes slightly beyond what I covered on Flask previously, but I will go into more details on Flask in subsequent posts.

The files for this tutorial are available here.