Day 17 (Part-2): Docker Project (Flask Calculator App)

Day 17 (Part-2): Docker Project (Flask Calculator App)

Project Overview:

This project is a simple calculator web application built using the Flask web framework in Python. The calculator allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, and division. Users can enter numerical values using the on-screen buttons or the keyboard, and the result of the calculation is displayed in the app.

Tasks:

  1. Pulling the calculator app image from Docker Hub: The first task was to pull the Docker image for the calculator app from Docker Hub. This involved running the docker pull command with the image name and tag.

  2. Creating an Nginx server block for hosting the app: The next task was to create an Nginx server block for hosting the app. This involved creating a new file in the /etc/nginx/sites-available/ directory with the server block configuration, which included the server name, the port to listen on, and the location block for the app.

  3. Writing the Dockerfile for the app: The next task was to write the Dockerfile for the app. This involved defining the base image, copying the app files into the container, and installing the Python requirements using pip, and exposing the port that the app listens on.

  4. Building the Docker container image: Once the Dockerfile was written, the next task was to build the Docker container image for the app. and create a container from it for app deployment.

Step-1 Install Docker into EC2 Instance:

apt-get install docker.io -y

Step-2 Clone Website content from Github:

git clone https://github.com/helloflask/calculator.git

Step-3 Create a Docker file to host the Website

here, I am creating a docker file to install nginx, configure sites-available and sites-enabled and other Python dependencies.

Docker image & container via commands - 2020

here, what I have done- install nginx, configure sites-available and other dependencies of Python:

Step-4 Create Nginx block for hosting website:

here, I have provided proxy_pass to my instance ip:

Step-5 Execute the Docker file for Image Creation:

What is Docker Container

docker build -t image1 .

Step-6 Verify the image and create a container:

docker run -it --name <container_name> <image_name> /bin/bash

Step-7 Run "nginx" & "flask" inside the container:

nginx -t 
service nginx start

Also, Run the Flask:

Step-8 Copy instance ip and check it onto Browser:

It's working

Step-9 Try to perform any mathematical operations to verify whether it connects to a database or not:

Try to add two digits '30' and '40'

Result:

"Please refer to my blog post titled 'Day 17 (Part 1)' for instructions on how to create an image from a container and push it to Docker Hub."

for more .... please follow my LinkedIn account

linkedin.com/in/abhijeet-singh-ba47b0252