# Day 19 - DevOps Project-1

## **Project Name - The Project involves deploying a DevOps Project on AWS ECS (Cluster/container orchestration) Fargate and AWS ECR (Registry like Docker Hub)**

# **Project Description**

Hello, everyone in this project we are going to get code from **GitHub** and make a docker image with the help of a docker file and push it into Amazon ECR(Elastic Container Registry) and then run this in Amazon ECS(Elastic Container Service) with the help of Fargate which is a serverless architecture through task definition.

### AWS Fargate

AWS Fargate is a serverless compute engine for containers that allows you to run Docker containers without managing the underlying infrastructure. It automatically provisions the required resources for your containers and integrates seamlessly with other AWS services, making it easy to deploy and manage container workloads at scale.

Fargate integrates seamlessly with other AWS services like ECS and EKS, enabling you to build scalable and highly available containerized applications.

By using Fargate, developers can enjoy the benefits of serverless computing for containers, such as reduced operational overhead, improved resource utilization, and simplified deployment workflows, ultimately allowing them to focus more on application development and innovation.

### What is ECS?

ECS stands for Elastic Container Service is a fully managed container orchestration service provided by AWS. It allows you to run, manage, and scale Docker containers in a highly scalable and flexible manner.

With ECS, you can easily deploy containers as tasks within clusters of EC2 instances or by utilizing AWS Fargate, a serverless compute engine for containers.

ECS offers features such as task definitions, which define container configurations, and services, which help with managing and scaling tasks. It provides fine-grained control over networking, security, and access control, ensuring reliable and secure container deployments at scale.

### What is ECR?

ECR stands for Elastic Container Registry, it is a fully managed Docker container registry provided by AWS. ECR allows you to store, manage, and deploy Docker container images, making it easier to build, test, and deploy applications using containers.

With ECR, you can securely store and share your container images, ensuring reliable access and high availability. It integrates seamlessly with other AWS services like ECS, EKS (Amazon Elastic Kubernetes Service), and CodePipeline, enabling streamlined container workflows.

ECR supports private repositories, fine-grained access control, image lifecycle management, and automatic encryption at rest.

By using ECR, developers can easily push, pull, and manage container images, while ensuring their availability, security, and scalability within the AWS ecosystem.

### **Prerequisite**

1. Create an EC2 instance in AWS management console. Navigate to the EC2 instance.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686734355549/aee9a583-4d84-45b7-9d56-3e5e5941923b.png align="center")

your instance is now up and running and initializing.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686734691286/408f4acd-4403-49a4-a844-3a9bcf5f174b.png align="center")

Fork the Repository and clone this GitHub Repository.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686735356133/69637434-e8f2-40eb-9436-96601bf43ef0.png align="center")

Connect this EC2 instance and clone this repository into your instance.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686735436142/ccc93c38-3b2b-488c-84d6-4f0d26356d9f.png align="center")

Go to ECR and Create a Public Repository in that.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686735907701/418d5b33-8cb8-41f3-b421-516196334262.png align="center")

Keep Repository as Public and give name to this Repository.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686736347417/608aa6e6-c502-4df2-976a-335140be812c.png align="center")

ECR public Repository is sucessfully created.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686736675902/99b1bd5b-c787-40b0-aaf3-73bb22beeb99.png align="center")

Go to IAM Security credentials and retrive Access key and Secret key.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686737341270/8fe55705-ea4d-4202-b58a-62f9d5e99175.png align="center")

First update the system

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686737736164/b5c2abcd-8646-4ef6-8a66-8007aaae61fe.png align="center")

Then install AWS CLI on it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686737881790/9e956ced-337a-4fe2-b856-c24b7d658f3c.png align="center")

Now Configure Aws and copy Access key and Secret key and paste on it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686738052646/23884cf4-7464-413b-b31e-df5dcd67231a.png align="center")

Go to ECR and click on View push command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686738428984/fe645b34-b7c0-4c81-92bc-0b1ae716ca11.png align="center")

After view push it will redirect into this page, Then copy this URL.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686738622237/e0dccf60-d461-4695-aac8-1f0abcc6f276.png align="center")

Go to the directory where your file is stored.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686739128879/4530b12b-f8bc-4676-a3e8-d93346b09866.png align="center")

Install docker in the server

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686739403155/a9989e86-7689-4015-9010-744855ab1c3f.png align="center")

Give the User permission to do this and Reboot it once.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686739550675/aeea488b-e8d2-45c0-9e12-837f37b5b1a5.png align="center")

Go to ECR click on view push commands and copy Url paste it then you will see Login is succeded.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686739692219/a5890900-b265-42fb-9cc5-63c0c96b2011.png align="center")

Go to view push command copy 2nd URL and paste into the server.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686739978897/6201357c-a3be-4124-b504-a858d2f237ec.png align="center")

You can see you successfully build the farget project.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686740153608/d13d92b4-8597-454f-af10-def73b58ee62.png align="center")

Copy 3rd URL and then paste it into server.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686740342100/181104c3-7b5c-4664-a28b-b4a3c756bc5d.png align="center")

Paste the docker tag url and also check whether your docker image is taged successfully or not by using **docker images** command

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686740627905/446e56cd-bb1c-4102-9c6d-8bb37462f1b1.png align="center")

Copy 4th docker push url

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686740723879/5377a4ea-d5f9-4c88-9568-7f8bcd68f95d.png align="center")

Paste docker push command into server and you have successfully push docker images.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686741043480/fe8a970b-3224-48de-abe5-2c2218e27a99.png align="center")

Go to ECR Repository which you created.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686741226177/31f9c420-4f5f-4cc2-9c45-7b991705a6b0.png align="center")

Click on the Repository name and you can see the image is pushed successfully into the Repository.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686741463335/b0167d4f-e748-4476-ab35-edf904f4df3a.png align="center")

Open Amazon Elastic Container Service and create cluster on it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686742046349/f7c05874-9472-4168-8b09-82d3f186894b.png align="center")

Give the name to the cluster and select VPC & infrastructure both are selected by default and then click on create.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686742420223/c0713ece-e677-4145-8b31-7dd99f8c79be.png align="center")

The cluster is created successfully.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686743186032/daef2a68-17b7-4a9b-acab-d8a33fca68da.png align="center")

Now click on Task definition and then create a new task definition, Give name to the task defination.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686744105263/ea2b87e8-33b2-4d1c-b5d8-be389c74ae67.png align="center")

Give name to the container paste ECR public image url and container port is 8000 bcoz we expose 8000 port in docker file. and go to Next

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686744310221/5c435147-97d5-43c3-aa5f-dd9b9cb53dbf.png align="center")

Task Defination is created successfully....

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686745139540/0f4ed116-7292-4208-8922-5e195b8c667c.png align="center")

Run a Task.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686745443539/08ee205b-0216-4909-af74-def2eab8f9f0.png align="center")

Create a Task for a particular cluster and click on create.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686745664788/12b4ada0-1713-4daf-9f87-b4dbf2bdb4ad.png align="center")

your task is up and Running state.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686746769486/3c647f7d-65d8-48c8-acae-1d7a616f51de.png align="center")

Add 8000 Port number on the security group.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686746620141/988eac0a-edd2-454c-9110-440eb73862ca.png align="center")

Go to the ECS Task which is up and running copy this public IP

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686746994208/acdfe980-d590-42a3-9b59-816dcd4f4359.png align="center")

Here we successfully deployed the application on ECS

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686749540400/577d0ceb-2fd9-4e67-9c5e-ee0eda456c1a.png align="center")

***Thank you for reading***
