Create Fargate Cluster and a Service which access Docker image with Nginx
Tags: docker, nginx, ecr, loadbalancer
Published: 2023-02-11 00:09:04

In this **3rd and last part of 3-part series on ECR Repository**, I am going to show you how to create a Fargate Cluster and a Service which uses the task definition that points to the image in the repository - nginx and access Docker image with Nginx from - Application Load Balancer and Fargate Cluster.

**Fargate** removes the need to provision and manage servers, lets you specify and pay for resources per application, and improves security through application isolation by design.

**1st article**
- As a reference, please read my **[1st article - How to create a Docker Image with Nginx from an EC2 Instance and Push to ECR Repository](https://dev.to/aws-builders/how-to-create-a-docker-image-with-nginx-from-an-ec2-instance-and-push-to-ecr-repository-nkb)**

**2nd article**
- As a reference, please read my **[2nd article -Create Task Definition in ECS and Application Load balancer (ALB) for the Task which is to be run on Fargate Cluster](https://dev.to/aws-builders/create-task-definition-in-ecs-and-application-load-balancer-alb-for-the-task-which-is-to-be-run-on-fargate-cluster-566m)**

_**Let’s get started!**_

Please visit my **[GitHub Repository for Docker/ECS/ECR articles](https://github.com/awsmine/Docker_projects)** on various topics being updated on constant basis.


# Objectives:

**1.** Create Fargate cluster - my-ecs-cluster

**2.** Create a Service - my-service

**3.** Validate by accessing Docker image with Nginx from - Application Load Balancer and Fargate Cluster.

**4.** Cleanup


# Pre-requisites:
- AWS user account with admin access, not a root account.
- AWS CLI.



# Resources Used:

**[Amazon Elastic Container Service](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html)**

**[AWS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/userguide/what-is-fargate.html)**

# Steps for implementation to this project:

## 1. Create Fargate cluster - my-ecs-cluster

- **`On the Amazon Elastic Container Service (ECS) Dashboard, Click Clusters, Create cluster, my-ecs-cluster, default vpc, 2 public subnets - us-east-1a, us-east-1b, Infrastructure - Your cluster is automatically configured for AWS Fargate (serverless)`** 

- Create 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6fojttxtiyipk8n235sv.png)


## 2. Create a Service - my-service

- **`Click my-ecs-cluster`**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/imb8hqk47g8iki5gd9y3.png)

- **`Take the below values for creating a Service - my-service`**

- **PHOTO-1**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y2x7q22bc9thly1y7g2r.png)


- **PHOTO-2**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8nlzyy5706dqc3fns5x5.png)


- **PHOTO-3**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aajscnwpkm51tzq0cyiz.png)


- **PHOTO-4**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jc0iacmajif8uzuo0go.png)



- **PHOTO-5**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ck1q4j1x8pgwthj1giwd.png)


- **PHOTO-6**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bf6962ai55q9of8z1lqn.png)


- Create


**my-service**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m5bglsdw2x69zn87tplz.png)


## 3. Validate by accessing Docker image with Nginx from - Application Load Balancer and Fargate Cluster.


- **`Click cluster - ecs-cluster, click tab - Tasks, Click the task, Copy the Public IP`**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1bnlezup6gr7t8wnssf.png)



- **`paste the Public IP on a web browser`**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6l91o1mo6ccjpyparzmh.png)


- **`Click my-ecs-alb, copy DNS name of ALB`** 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj0iojkmqzg0sjk4x7xe.png)


- **`paste DNS name of ALB on a Web browser`**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d214dzskyrtdgzzjgpks.png)

## 4. Cleanup

- **`on the service - my-service, Desired-task - 0, Update`**

- then delete service, task, cluster, Load balancer, Target groups, EC2 instance, and service group

# What we have done so far

- We have successfully created a Fargate Cluster and a Service which uses the task definition that points to the image in the repository - nginx and accessed Docker image with Nginx from - Application Load Balancer and Fargate Cluster.