Docker Project for Devops

ยท

2 min read

DockerFile

  • A Dockerfile is a text file used to define the instructions for building a Docker image. It provides a set of steps that Docker follows to create an image, which can then be used to run containers.

  • In a Dockerfile, you specify the base image, add additional dependencies and files, set environment variables, and define the commands to run when starting a container from the image. The Dockerfile acts as a recipe for building a Docker image with all the necessary components and configurations.

Here are some key reasons to use Dockerfiles:

  1. Reproducibility and Consistency: Dockerfiles ensure reproducibility by capturing the exact steps and configurations needed to build an image by defining the precise versions of software packages, libraries, and dependencies required by your application.

  2. Automation: Dockerfiles allow for automated image builds. By defining the build steps in a Dockerfile, you can automate the image creation process, reducing manual effort and the risk of human error.

  3. Customization and Configuration: Dockerfiles provide flexibility in configuring the application environment. You can define specific settings, environment variables, and file placements within the image.

  4. Scalability and Deployment: Dockerfiles facilitate the scaling and deployment of containerized applications. By defining the build process in a Dockerfile, you can easily create multiple instances of the same image, allowing for horizontal scaling of your application.

Deploying Project

Project : Node Todo App

Node Todo App Repository

Cloning the Node Todo application from git and removing the existing Dockerfile.

  1. Create a new Dockerfile to write the set of instructions for execution

    2.Create a container from the built application/image

    3.Checking the images

      docker images
    

    4.Create a container from the built application/image

      docker run -p 8000:8000 -d node_todo_app:latest
    
    1. Now edit the inbound rule for mapping the port number 8000 so that it will be shown using public IPv4.

        # Follow the steps:
        # EC2 -> Security -> Security Groups -> Inbounds Rules-> Edit -> Add a rule
      
        Type: Custom TCP
        Port Range : 8001
        Source Tyep : Anywhere-IPv4
      
        Now save the Rule
      

    2. Now copy the public ipv4 address and pass the port number to view the application.

      Public_IPv4_URL:<Port_number>

    3. Now we can see the containers up & running in port 8000

        docker ps
      

Thanks for Reading!๐Ÿ˜Š

ย