Deploying a Docker Container With Amazon ECS and Fargate

Chakresh Tiwari
ShoutLoudz
Published in
5 min readMar 31, 2024

Introduction

In the previous posts, we have learned how to create a docker image of the Spring boot app and how to publish it on Dockerhub.

Now after publishing the image to Dockerhub, the Next step is to create a container using that image and run it using AWS ECS and Fargate.

AWS Elastic Container Service(ECS)

ECS (Elastic Container Service) is a fully managed container orchestration service. That helps you easily deploy, manage and scale containerised applications.

As a K8s service managed by AWS, it comes with all the best practices. It’s integrated with both the Elastic Container Registry (ECR) and Docker.

It helps teams in building apps instead of the environment to run.

There are three layers in Amazon ECS:

  1. Capacity
  2. Controller — ECS scheduler manages the application
  3. Provisioning — Provisioning can be done using any way like from the management console SDK, CLI or Copilot

Elastic Container Service Capacity is the infra where your containers run.

  1. EC2 — These are servers which are managed by users.
  2. AWS Fargate — It is a serverless offering from AWS, where users do not need to manage servers.
  3. On-Prem VM

Fargate

AWS Fargate is a technology to run containers using Amazon ECS without managing servers or clusters of Amazon EC2.

Fargate removes all the manual work which we need to do, like managing clusters or servers, and scaling up or down.

We don’t need to manage (provision, configure or scale) clusters of virtual machines to run containers.

We need to package our application in containers and tell how much CPU and memory we need to run our application. and define networking and IAM policies and just run the application.

You can check usage metrics in CloudWatch.

After understanding about AWS ECS and Fargate now let’s deploy our Image using ECS.

These are the following steps which we need to follow while deploying applications in ECS using Fargate:

  1. Search ECS in the search Menu in AWS.
  2. There are options like Clusters, Namespaces and Task Definition.
  3. First, we go to the task Definition Tab and Provide the details like Infrastructure Details like Memory and vCPU configuration and after that container details like image URL and container name. (Task Def is something where we provide how much memory to allocate, and how many containers will run.)

4. After Providing task Definition now create a Cluster by providing details like name and Infra details. An Amazon ECS cluster groups together tasks and services, and allows for shared capacity and common configurations. All of your tasks, services and capacity must belong to a cluster.

5. After Cluster creation create a service to run task Definitions on that cluster. (To run a task we need service and to start a service we need a cluster). service launches the task using task definitions.

6. While Configuring the service keep in mind to Click on the checkbox to get A public IP using the public IP we can access our application APIs from the browser.

7. To Access the public IP from the browser we need to provide an inbound rule in the security group(the same security group should be used with the service, which we configured while creating the service) which allows all the IPs to access our public IP.

8. After this copy the public IP and hit the API and we will get the response in the browser. This way even if one of the tasks goes down because of some reason our service will create a new task automatically and our application will continue running.

You must architect your application in such a way that it can run on containers. The container is a standardised unit of software development.

So by following the above steps, we can launch our application on AWS using ECS and Fargate.

Next, we will learn topics like Container Orchestration using K8s, Docker Swarm, EKS, CI/CD pipelines and then usage of these concepts in Microservice Architecture.

Now to launch the application we need to learn programming languages and concepts. I would recommend following these tutorials for better understanding.

Learn Java for free with 🤖 Travis | your AI-powered tutor. 📚 150K free learning resources | 🔀 interactive roadmaps | 🤖 AI-powered tutoring.

Learn Python for free with 🤖 Travis | your AI-powered tutor. 📚 150K free learning resources | 🔀 interactive roadmaps | 🤖 AI-powered tutoring.

Thanks for reading!!

--

--

Chakresh Tiwari
ShoutLoudz

Software Engineer at Cisco(Appdynamics) , Sharing my knowledge and experience related to work. I am here to help learners to prepare for tech interviews.