Getting Started with Docker and Flask

Overview

Getting-Started-with-Docker-and-Flask

Introduction

Docker makes it easier, simpler and safer to build, deploy and manage applications in a docker container. This article will help you get a detailed understanding of;

  • What is docker?
  • Why use Docker?
  • What is a docker image?
  • What is a docker container?
  • Dockerizing a flask application
What is Docker?

Docker is an open source containerization platform for developing, shipping and running applications.

Docker packages software into standardized units called containers. Containers have everything the software needs to run including libraries, system tools, code, and runtime.

More about what docker is

Why use Docker?
  • Responsive deployment and scaling.
  • Faster And Consistent Delivery Of Applications.
Docker image.

Image is a read-only template with instruction for creating containers. Docker images can be considered as the blueprint of the entire application environment that you create.

Docker container.
  • A Docker container is a virtualized run-time environment where users can isolate applications from the underlying system.
  • Containers are compact, portable units in which you can start up an application quickly and easily.
  • Docker containers contains all the essential things required to run an application like code, runtime, system tools, system libraries, and settings.
Dockerizing a flask application
File structure and setup
\-- dockerExample
    |-- app.py
    |-- Dockerfile
    |-- requirements.txt
   \-- templates
        |-- index.html
        

First I created a simple Flask application and added the following code to app.py.

from flask import Flask,render_template
app=Flask(__name__)

@app.route('/')
def home():
    return render_template('index.html')

if __name__==('__main__'):
    app.run(debug=True)

Check how to create a simple flask application

Add the following code to index.html

>
<html>
<head>
<title>Getting started with Dockertitle>
head>
<body>
<p>This is my Dockerfilep>

body>

Now we need to dockerize the flask application by creating a Dockerfile Dockerfileis a text document that contains all the commands a user could call on the command line to assemble an image.

Add the following code to docker;

FROM python:3.9.6
COPY . /doc
COPY ./requirements.txt /doc/requirements.txt
WORKDIR /doc
EXPOSE 5000:5000
RUN pip install -r requirements.txt
CMD ["python","app.py"]
  • FROM keyword is used to specify the base image to be used. We'll be making use of a python base image.
  • WORKDIR defines the main directory of operations.
  • EXPOSE informs Docker that the container listens on the specified network ports at runtime.
  • RUN is used to install the project’s dependencies.
  • CMD provide defaults for an executing container.

Read more

We can now build our image with the docker build command as shown below;

docker image build -t docker_example .

Screenshot (119)

Once the build process is done, we can run the application with the docker run command as shown below;

docker run -p 5000:5000 docker_example

Screenshot (122)

Owner
Phylis Jepchumba
Software Engineer||Technical writer||Community manager
Phylis Jepchumba
SQLAlchemy database migrations for Flask applications using Alembic

Flask-Migrate Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic. The database operations

Miguel Grinberg 2.2k Dec 28, 2022
Full text search for flask.

flask-msearch Installation To install flask-msearch: pip install flask-msearch # when MSEARCH_BACKEND = "whoosh" pip install whoosh blinker # when MSE

honmaple 197 Dec 29, 2022
YAML-formatted plain-text file based models for Flask backed by Flask-SQLAlchemy

Flask-FileAlchemy Flask-FileAlchemy is a Flask extension that lets you use Markdown or YAML formatted plain-text files as the main data store for your

Siddhant Goel 20 Dec 14, 2022
Paid roles for discord using Stripe, Python, Flask & Docker

Welcome to Paycord Paid roles for discord using Stripe, Python, Flask & Docker. Setup Production On stripe dashboard, go Developers ➡️ Webhooks ➡️ Add

Ward 12 Dec 28, 2022
A simple application builder. Made with python.

Python Flask Server Template Check the Github Repository for updates Flask is an application builder. It is very common in Python but can also be used

1 Jan 09, 2022
Flask app for deploying DigitalOcean droplet using Pulumi.

Droplet Deployer Simple Flask app which deploys a droplet onto Digital ocean. Behind the scenes there's Pulumi being used. Background I have been Terr

Ahmed Sajid 1 Oct 30, 2021
Search users in Github. Created with Flask, PipEnv, Heroku and free time.

Search in Github Here search for users in Github and other stuff! This app is working with, Data Github API BackEnd Flask Language Python Package mana

AmirHossein Mohammadi 12 Jan 16, 2022
SeCl - A really easy to deploy and use made-on Flask API to manage your files remotely from Terminal

SeCl SeCl it's a really easy to deploy and use made-on Flask API to manage your

ZSendokame 3 Jan 15, 2022
Small flask based opds catalog designed to serve a directory via OPDS

teenyopds Small flask based opds catalog designed to serve a directory via OPDS, it has currently only been verified to work with KyBook 3 on iOS but

Adam Furbee 4 Jul 14, 2022
Connect is a Python Flask project within the cloud-native ecosystem

Connect is a Python Flask project within the cloud-native ecosystem. Second project of Udacity's Cloud Native Nanodegree program, focusing on documenting and architecting a monolith migration to micr

Lauren Ferreira 3 Feb 28, 2022
i18n and l10n support for Flask based on Babel and pytz

Flask Babel Implements i18n and l10n support for Flask. This is based on the Python babel module as well as pytz both of which are installed automatic

397 Dec 15, 2022
A multi-container docker application. Implemented and dockerized a web-based service leveraging Flask

Flask-based-web-service-with-Docker-compose A multi-container docker application. Implemented and dockerized a web-based service leveraging Flask. Des

Jayshree Rathi 1 Jan 15, 2022
Library books management program, built with Flask, Python

Library books management program, With many features and good User Interface. built with Flask, Python. (Include Screenshots) and documentation on how to run it! Thank you :)

Thierry Mugisha 1 May 03, 2022
Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure.

Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure. All the required libraries are already installed easily to use in any big project.

Ajay kumar sharma 5 Jun 14, 2022
A simple example using Flask inside a container

This is a simple example of how create a container for a Python Flask Web Application using Docker.

Fazt Web 8 Aug 30, 2022
An Instagram Clone using Flask, Python, Redux, Thunk, React

An Instagram Clone using Flask, Python, Redux, Thunk, React

1 Dec 09, 2021
Flask-Starter is a boilerplate starter template designed to help you quickstart your Flask web application development.

Flask-Starter Flask-Starter is a boilerplate starter template designed to help you quickstart your Flask web application development. It has all the r

Kundan Singh 259 Dec 26, 2022
A boilerplate Flask API for a Fullstack Project :rocket:

Flask Boilerplate to quickly get started with production grade flask application with some additional packages and configuration prebuilt.

Yasser Tahiri 32 Dec 24, 2022
Boilerplate template formwork for a Python Flask application with Mysql,Build dynamic websites rapidly.

Overview English | 简体中文 How to Build dynamic web rapidly? We choose Formwork-Flask. Formwork is a highly packaged Flask Demo. It's intergrates various

aswallz 81 May 16, 2022
A service made with Flask and Python to help you find the weather of your favorite cities.

Weather-App A service made with Flask and Python to help you find the weather of your favorite cities. Features Backend using Flask and Jinja Weather

Cauã Rinaldi 1 Nov 17, 2022