Docker Project for DevOps Engineers

📁DockerFile:
A Dockerfile is a text file that contains instructions to build a Docker image. Here's a simplified explanation in five lines:
A Dockerfile specifies a base image to start with, usually an existing operating system or application.
It defines a series of instructions to install dependencies, copy files, configure settings, and execute commands within the image.
Each instruction creates a new layer in the image, allowing for incremental builds and efficient resource utilization.
Dockerfiles include commands to expose ports, set environment variables, and define entry points for running the containerized application.
Once the Dockerfile is ready, it can be used to build a Docker image using the "docker build" command, which encapsulates the application and its dependencies into a portable and reproducible package.
🌎Task: Deploying Projects
🌟Project: Django_todo_cicd app
React Django Application Repository:
step 1: Cloning the react django application from git and removing the existing Dockerfile.
mkdir project cd project git clone https://github.com/PrabirKumarMahatha/django-todo-cicd cd django-todo-cicd rm Dockerfile #because i have docker file already. we have to build a dockerfile by own

step 2: Create a new Dockerfile to write the set of instructions for execution:
to create a Dockerfile run command
vim dockerfileWrite this code to the Dockerfile:
```bash FROM python:3 RUN pip install django==3.2
COPY . .
RUN python manage.py migrate EXPOSE 8000 CMD ["python","manage.py","runserver","0.0.0.0:8000"]

<mark>step 3:</mark> Now we have to build the application by providing the image & tag name
```bash
docker build . -t django_todo_cicd:latest
# -t is used for tagging
# we use . as Dockerfile is same dir. But if it is in different dir we have to pass the absolute path of Dockerfile
# To create a Docker file and from the Dockerfile we create an image
# From the image we can create a container
# succssfully tagged message should come atlast

step 4:Create a container from the built application/image
docker run -p 8000:8000 -d react_django_app:latest

step 5: Check the container is up & running in port 8001
docker ps

step 6: Now we have to map our URL in the EC2 instance so that app can run on a Public IPv4 port.
# Follow the steps:
# EC2 -> Security -> Security Groups -> Inbounds Rules-> Edit -> Add a rule
Type: Custom TCP
Port Range : 8000
Source Tyep : Anywhere-IPv4
Now save the Rule


step 7: Now copy the public ipv4 address and pass the port number to view the application.
Public_IPv4_URL:<Port_number>

Push the image to a public or private repository (e.g. Docker Hub )
step 1: For push the image into docker hub you must have an account on docker hub .
if you dont have an account on docker hub read the privious blog . To read the blog click here
once you created an account on docker hub , log in into docker hub in terminal
to log in run the following command
sudo docker login
# run this command and filled the userid ,password to log in

step2: Creating the new image name for the existing container
# Checking the image name
docker ps
# Giving new image name to the existing one
sudo docker image tag django_todo_cicd:latest prabirmahatha/django_todo_cicd:latest

step3: Push the image from local to remote
sudo docker push prabirmahatha/django_todo_cicd:latest

step 4: Now from the DockerHub dashboard, we can view our deployed image.

🥳🥳🥳🥳Congo! you did it successfully

For another docker project.
Follow me on LinkedIn to see interesting posts like this : )
linkedin.com/in/prabir-kumar-mahatha-6a0025..
visit my git hub profile: github.com/PrabirKumarMahatha





