Containerizing the WebApp using Docker: End-to-End Series (Part — 5)

Accredian Publication
3 min readMar 12, 2021


By Hemanka Sarmah

In our previous article, we deployed our flask app on the local server using gunicorn.
Now, we will look at how to containerize the application using docker.

What is Docker?

Docker is a software platform for building applications based on containers — small and lightweight execution environments that make shared use of the operating system kernel but otherwise run in isolation from one another.

Advantages of using Docker

  • Efficient use of system resources
  • Faster software delivery cycles
  • Application portability increases
  • Faster deployment
  • Repeatability and automation

Also, Check out our Article on:

  1. Data Abstraction: End-to-End Series (Part — 1)
  2. Data Preprocessing and EDA: End-to-End Series (Part — 2)
  3. Model Building and Experimentation: End-to-End Series (Part — 3)
  4. Creating a WebApp using Flask+Gunicorn on Ubuntu Server: End-to-End Series (Part — 4)
  5. Scaling our Docker Container using Kubernetes: End-to-End Series (Part — 6)
  6. Automating building and deployment using Jenkins: End-to-End Series (Part — 7)

Installing Docker in a Windows machine

For people using windows 10 machine, please refer to this link and follow the steps.

Creating a Dockerfile

  • To create a docker file open notepad and type the below command.
FROM python:3.9COPY requirements.txt /RUN pip3 install -r /requirements.txtCOPY . /appWORKDIR /appEXPOSE 8000CMD gunicorn flaskapp:app --bind -w 5 --threads 3
  • Then click on Save as and make sure to name it “Dockerfile” without any extension.
  • Then choose All files in the save as type and save the file in the location where all the files are present.
  • Save it in the directory where every file is present.
  • Static folder contains images
  • templates contain HTML file.

Building an image

  • Open CLI and navigate to the folder location containing all the files and type the below command.
docker build -t flask-app .
  • Once the image is created you can verify it with the command.
    docker images

Running the image in the local

docker run -it -d --rm -p 8000:8000 <image_id>
  • Once the container starts running you can check logs of any container by the command.
    docker logs <container_ID>

Checking the running app in the system

Just go to your browser and type:


You will be able to access the web app from the local ip.

Follow us for more upcoming future articles related to Data Science, Machine Learning, and Artificial Intelligence.

Also, Do give us a Clap👏 if you find this article useful as your encouragement catalyzes inspiration for and helps to create more cool stuff like this.

Visit us on



Accredian Publication

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!