DevOps(Day-17) : Docker Project - Flask Calculator App

DevOps(Day-17) : Docker Project - Flask Calculator App

TABLE OF CONTENTS

Docker plays a major role in building the application by improving its efficiency. It containerizes the application by creating an image which is portable i.e. can be run anywhere in any specification of the server.

Here comes the base of Docker which is called a Docker file. Let's learn what is it and how it sets a standard from application to apply through its configuration.

DOCKER FILE

A docker file is a text file with a set of information that Docker reads to build an image about it. The file contains similar commands as we give CLI commands to build an image manually but here we combine all the steps to execute at a time.

The format for writing the docker file is:-

Environment variables are supported by the following list of instructions in the Dockerfile :

  • ADD - It gives instructions to copy new files, directories, or remote file URLs and then adds them to the filesystem of the image.

  • COPY - It is used to copy files and directories inside a Docker Container from your Local machine.

  • ENV - It sets the environment variables both during the build and when running the result.

  • EXPOSE - It assigns a port to the container.

  • FROM - It sets the base image or the environment of the Docker file on which the command will need to run.

  • RUN - It executes the commands through the shell. It tells what process will be running inside the container at the run time

  • CMD - It specfifies whole command to run. It is the default argument to the ENTRYPOINT.

  • ENTRYPOINT - It passes the command that will run on the start of the Docker file.

  • LABEL - It is used to provide your customizable metadata that will be set for the container.

  • USER - It sets which user’s container will run as.

  • VOLUME - It is used to map host path to a container. It is also used to create new volume that can be used by later containers.

  • WORKDIR - It sets the directory that the container starts in

Now, let's do some hands-on with a small project.

  • ADD - It gives instructions to copy new files, directories, or remote file URLs and then adds them to the filesystem of the image.

  • COPY - It is used to copy files and directories inside a Docker Container from your Local machine.

  • ENV - It sets the environment variables both during the build and when running the result.

  • EXPOSE - It assigns a port to the container.

  • FROM - It sets the base image or the environment of the Docker file on which the command will need to run.

  • RUN - It executes the commands through the shell. It tells what process will be running inside the container at the run time

  • CMD - It specfifies whole command to run. It is the default argument to the ENTRYPOINT.

  • ENTRYPOINT - It passes the command that will run on the start of the Docker file.

  • LABEL - It is used to provide your customizable metadata that will be set for the container.

  • USER - It sets which user’s container will run as.

  • VOLUME - It is used to map host path to a container. It is also used to create new volume that can be used by later containers.

  • WORKDIR - It sets the directory that the container starts in

Now, let's do some hands-on with a small project.

PROJECT: Build a container for a Flask Calculator App

  • Let's bring the code and push it to local from remote GitHub repository. The link of my GitHub is below:

  • github.com/Biswaraj/flask-calculator

  • Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)

  • Open the inbound port in the AWS security group of the server.

  • Build the image using the Dockerfile and run the container

  • Verify that the application is working as expected by accessing it in a web browser

  • Push the image to a public or private repository (e.g. Docker Hub )

  • It always feels good to build a project. Hope you find it interesting.

    Thanks for reading my article. Have a nice day.

  • WRITTEN BY Biswaraj Sahoo --AWS Community Builder | DevOps Engineer | Docker | Linux | Jenkins | AWS | Git | Terraform | Docker | kubernetes

    Empowering communities via open source and education. Connect with me over linktree: linktr.ee/biswaraj333