# Docker Project for Devops

### **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**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683259612562/b97d66de-1c5c-445e-bad9-fdd410a62938.png?auto=compress,format&format=webp align="left")

[**<mark>Node Todo App Repository</mark>**](https://github.com/LondheShubham153/node-todo-cicd)

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

1. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683288563245/03ba09fd-b687-4ba9-8a9e-95769c5236c6.png align="center")
    
    Create a new Dockerfile to write the set of instructions for execution
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683288593278/e91d6449-4fb8-4749-a39e-bf7db0ac3312.png align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683288720445/bb4cffca-ada2-4787-b153-a8bccc02b128.png align="left")
    
    2.Create a container from the built application/image
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683288828549/83573f95-f87f-4729-b82b-5c1dcd7f8887.png align="center")
    
    3.Checking the images
    
    ```plaintext
     docker images
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683288967831/569963ad-4baf-471e-95f4-e2eccb15ec92.png align="center")
    
    4.Create a container from the built application/image
    
    ```plaintext
     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.
        
        ```plaintext
         # 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
        ```
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682832143925/2593b147-0690-4fe3-898e-e884821800c8.png?auto=compress,format&format=webp align="left")
        
    2. Now copy the public ipv4 address and pass the port number to view the application.
        
        Public\_IPv4\_URL:&lt;Port\_number&gt;
        
    3. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683289233731/fb306474-1383-47f4-bd96-a9efc8eb5957.png align="left")
        
    4. Now we can see the containers up & running in port 8000
        
        ```plaintext
         docker ps
        ```
        
    
    **Thanks for Reading!😊**
