This is a view counter app that is written in Python using Flask framework, packaged using Docker.
@Todo - the minimal set up to start the project. Something like:
$ git clone repo
$ docker-compose up --build
At this point, the app runs at localhost:5000
Make sure to have Python installed and its package manager, pip
.
python --version
pip --version
If the above command yields an error, install Python.
sudo apt install python3 python3-pip
sudo yum install python3 python3-pip
Refer to your Linux distribution's documentation for how to install Python.
python3 -m venv venv
source venv/bin/activate
pip install flask
Then you can import Flask in your code.
import flask
project-name/ # The project's root directory
└───src/ # The project's app directory
├───init.sql # Initial database
├───requirements.txt # Requirements for the project
└───main.py # Main app
This is packaged by using the Python container image as a base, copying the source code and installs necessary dependencies of this app and adds a startup script.
There are 2 modes for running this project, "development" and "production", It's up to the developers to define how their apps would behave under development environment and production environment. For example, development mode may use SQLite as a database whereas in production, the app will use PostgreSQL.
In production, Gunicorn is used as the server and bytecodes will be generated from the source code for faster startup whereas in development, a development server from Flask is used.
docker-compose up --build
Docker images can be customized using environment variables or customized during build time using build arguments.
Key | Description |
---|---|
MYSQL_HOST |
Hostname of the database server. |
MYSQL_USER |
Username that will be used to log in into the database server. |
MYSQL_PASSWORD |
Password that will be used to log in into the database server. |
MYSQL_DATABASE |
Database that will be used for storing data. |
BIND_ADDR |
IP Address to bind into. |
Key | Description |
---|---|
PYTHON_VERSION |
The version of Python that will be used for building this image, note that Python 2 is not supported. |