DEV Community

loading...
Cover image for Flask Dashboard - Execution with Docker

Flask Dashboard - Execution with Docker

Sm0ke
#Automation, my favorite programming language
Updated on ・5 min read

Hello Coders,

This article presents an open-source Flask Dashboard configured to run in Docker. The curious minds can download this sample directly from Github (no account required) and use it for hobby & commercial projects. For newcomers, Flask is a lightweight web application framework written in Python. Sometimes classified as a microframework, Flask provides a lightweight codebase that can be easily extended to become an API, a simple web app, or a complex eCommerce platform.

Thanks for reading! TL;DR;



To locally build and execute the Flask application used as a sample in this article { Flask Dashboard Black } is quite simple:

  • Make sure you have a Python environment up & running
  • Clone the open-source project
  • Install the modules required by the app
  • Prepare the environment by setting the FLASK_APP variable
  • Start the app using the flask embedded server flask run

In our local environment, usually (not always) things are fairly simple and we will see the app running in the browser without much effort. The real issues might hit us hard when we want to release the app in the public space, using a production server.

Docker, properly set up on top of our application should make this deployment much easier. A few advantages provided by this virtualization model:

  • The App is executed isolated without damaging or interfering other apps or services
  • The management layer (start/stop the app) is at Docker level now - super easy to manage
  • Multiply app instances by using multiple Docker containers with ease

Enough talking, let's see something beautiful on our screen executed with Docker, in less than two minutes. In case you don't have Docker installed in the workstation, please navigate to their website and follow the installation instructions suitable for your OS: Mac, Linux (Ubuntu) or M$ Windows and get back here when it's done.

The Flask Dashboard used a sample is an open-source admin panel coded on top of a beautiful Black Design crafted by Creative-Tim agency.


Flask Dashboard - Docker execution

Get the code

$ git clone https://github.com/app-generator/flask-black-dashboard.git
$ cd flask-black-dashboard
Enter fullscreen mode Exit fullscreen mode

Install Docker modules (Nginx, Gunicorn)

$ sudo docker-compose pull
Enter fullscreen mode Exit fullscreen mode

Set up the app inside the Docker container

$ sudo docker-compose build
Enter fullscreen mode Exit fullscreen mode

Start the Docker container

$ sudo docker-compose up 
Enter fullscreen mode Exit fullscreen mode

Visit http://localhost:5005 in your browser. You should see a nice screen like this one:

Flask Dashboard Black - Executed in Docker

We can see that the usual steps to install the modules, set up the environment and configure Gunicorn to exec the app, has gone. To make this happen, this app has already some useful files configured to make our lives easier, thanks to Docker.


What happens under the hood

  • Docker pull the images for Nginx and Gunicorn
  • The Python modules required by the app are installed inside the container
  • The environment is updated with necessary variables
  • Start the app using Gunicorn
  • Start Nginx and link the proxy server to our app
  • Expose the port 5005 outside container

Relevant files


Other Useful commands

Start the container - daemon mode

The previous command sudo docker-compose up will lock the terminal. In case we want to execute the container as a background process -d must be used as an argument.

$ sudo docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Stop the Docker container

$ sudo docker-compose down 
Enter fullscreen mode Exit fullscreen mode

Personally, I found Docker super convenient for Python-based apps deployment (e.g Flask & Django apps) and to make my life easier, I've cloned this set up for more free & open source Flask Dashboards, listed below:


Flask Dashboard Argon

An open-source admin panel coded in Flask on top of Argon Dashboard design (free version) - UI Credit Creative-Tim.

Use with Docker

$ # Clone the sources
$ git clone https://github.com/app-generator/flask-boilerplate-dashboard-argon.git
$ cd flask-boilerplate-dashboard-argon
$
$ # Start the app in Docker
$ $ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up
Enter fullscreen mode Exit fullscreen mode

Flask Dashboard Argon - Open-Source Flask Boilerplate.


Flask Dashboard Atlantis Dark

A super simple open-source admin dashboard coded in Flask Framework on top of Atlantis Dark Dashboard design (free version).

Use with Docker

$ # Clone the sources
$ git clone https://github.com/app-generator/flask-dashboard-atlantis-dark.git
$ cd flask-dashboard-atlantis-dark
$
$ # Start the app in Docker
$ $ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up
Enter fullscreen mode Exit fullscreen mode

Flask Dashboard Atlantis Dark - Open-Source Flask Dashboard.


Flask Dashboard Light Blue

Free admin dashboard designed by FlatLogic and coded in Flask.

Use with Docker

$ # Clone the sources
$ git clone https://github.com/app-generator/flask-dashboard-light-blue.git
$ cd flask-dashboard-light-blue
$
$ # Start the app in Docker
$ $ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up
Enter fullscreen mode Exit fullscreen mode

Flask Dashboard Light Blue - Open-Source Dashboard.


Flask Dashboard Now UI

A super nice Dashboard design coded in Flask - MIT License.

Start with Docker

$ # Clone the sources
$ git clone https://github.com/app-generator/flask-now-ui-dashboard.git
$ cd flask-now-ui-dashboard
$
$ # Start the app in Docker
$ $ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up
Enter fullscreen mode Exit fullscreen mode

Flask Dashboard Now UI - Open-Source Flask Dashboard.


Well, that's all coders. For more free, open-source admin dashboards please access the AppSeed platform or Github.


Credits & Resources

Flask Framework

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.

Docker

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.


Thanks for reading! AMA in the comments.

Discussion (0)