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
Flask extension that takes care of API representation and authentication.

Flask-API-Utils Flask-API-Utils helps you to create APIs. It makes responses in appropriate formats, for instance, JSON. All you need to do is to retu

Marsel Mavletkulov 55 Aug 28, 2022
An extension to add support of Plugin in Flask.

An extension to add support of Plugin in Flask.

Doge Gui 31 May 19, 2022
Full-Stack application that visualizes amusement park safety.

Amusement Park Ride Safety Analysis Project Proposal We have chosen to look into amusement park data to explore ride safety relationships visually, in

Michael Absher 0 Jul 11, 2021
MongoEngine flask extension with WTF model forms support

Flask-MongoEngine Info: MongoEngine for Flask web applications. Repository: https://github.com/MongoEngine/flask-mongoengine About Flask-MongoEngine i

MongoEngine 815 Jan 03, 2023
Basic flask system for login, api, and status system

Flask Multi Site With Login This is a basic website login system with an uncomplete api system NOTICE : This is NOT complete and is made to be a bare

MrShoe 0 Feb 02, 2022
Adds Injector support to Flask.

Flask-Injector Adds Injector support to Flask, this way there's no need to use global Flask objects, which makes testing simpler. Injector is a depend

Alec Thomas 246 Dec 28, 2022
A Cyberland server written in Python with Flask.

Cyberland What is Cyberland Cyberland is a textboard that offers no frontend. Most of the time, the user makes their own front end. The protocol, as f

Maxime Bouillot 9 Nov 26, 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
Guitar tabs web app for guitar fans, powered by Python/Flask

Guitar123 version 0.8.5 Guitar tabs web app for guitar fans, powered by Python/Flask Features Guitar tabs search and browse Easy to use for end user a

lowrain 48 Dec 27, 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
API to get the details of the characters in the Money heist TV show.

Project Heist Description: Project Heist is a RESTful API made using Python and Flask. This API is inspired by the popular Spanish TV show Money Heist

Rahul V 5 Dec 19, 2022
A Python, Flask login system

Python Login System This is a basic login + authenticason system for flask using Flask_Login and Flask_SQLAlchemy Get started on your own To use this

MrShoe 0 Feb 02, 2022
Rate Limiting extension for Flask

Flask-Limiter Flask-Limiter provides rate limiting features to flask routes. It has support for a configurable backend for storage with current implem

Ali-Akber Saifee 922 Jan 08, 2023
retorna informações de pessoas que não existem

random-person-api API que entrega dados aleatórios sobre pessoas que (provavelmente) não existem. Como usar? Copie o link abaixo https://random-person

Miguel 3 Aug 09, 2022
A gRpc server like Flask (像Flask一样的gRpc服务)

Mask A gRpc server just like Flask. Install Mask support pypi packages, you can simply install by: pip install mask Document Mask manual could be fou

吴东 16 Jun 14, 2022
A clean and simple blog system based on Flask and MongoDB

CleanBlog A clean and simple blog system based on Flask and MongoDB You can access CleanBlog This is the source code of Flask Tutorial Pro,you can buy

shin 107 Oct 06, 2022
Python3🐍 webApp to display your current playing music on OBS Studio.

Spotify Overlay A Overlay to display on Obs Studio or any related video/stream recorder, the current music that is playing on your Spotify. Installati

carlitos 0 Oct 17, 2022
A web application for a fake pizza store, built in Python with Flask and PostgreSQL.

✨ Pizza Pizza - Pizza Store ✨ A web application for a fake Pizza Store, the app let you create an account and order pizza, complements or drinks. Buil

Bonnie Fave 6 Dec 18, 2022
An flask app for fake image detector

fake_img_detector This is a ml based project: frameworks used:- Flask Google collab #Description: Here you can Upload two different looking image with

shivam kumar 7 Jun 29, 2022
Simple flask api. Countdown to next train for each station in the subway system.

Simple flask api. Countdown to next train for each station in the subway system.

Kalyani Subbiah 0 Apr 17, 2022