This tutorial covers simple steps to build and deploy a Flask application using Docker on Ubuntu 18.04. The sample application process data stored in a JSON file format and displayed on the browser.
Docker is an open-source platform to develop, manage, and deploy applications using containers. For Docker installation, refer to this article.
Flask is a web micro-framework built on Python.
Step 1: Create a Dockerfile.
Dockerfile is a first step to containerize an application. Dockerfile contains a list of commands to assemble an image.
Step 2: Create a configuration file to install Flask framework of version 0.10.1
file name: requirements.txt
Step 3: Create a sample JSON data file.
file name: file.json
Step 4: Write Python code to process JSON file data and flush out output to index.html.
file name: app.py
Step 5: Index.html file render and display extract on the browser.
file name: Index.html
Step 1 through 5 setup code and configuration of a Flask application on docker. Now execute the below-mentioned docker command to install and run the sample application.
$docker build -t flask_json:latest
$docker run -p 5000:5000 flask_json
In this step, you have successfully deployed the sample Flask application on Docker. Below command to verify container run.
$docker ps -a
Lastly, now check application is running; visit the IP address(0.0.0.0:0000) at your browser.
These basic steps can get you started with the initial setup of a Flask application. This application can further scale to store data into a persistent source and furthermore.