How to deploy a Docker container running an API to Fargate with a Load Balancer

Ankit Sharma Oct 30 2021 · 3 min read
Share this

First sign in using your credentials in AWS CLI on your device. Make sure docker is running on your device.

Build and push your Docker image to ECR(Elastic Container Repository)

Go to AWS ECS (Elastic Container Service) and create a cluster

Choose Networking Only

FIrst we need to create a task definition which will have the details about the container which is going to run.

Choose fargate


Fill the basic details 

Time to attach the docker image to this task definition

COPY the repository URI from the ECR tab

Paste the URI inside image input and your application port in Port Mappings and Create the Task definition

Now go to your cluster and create a service which will run the task

Configure your service and choose the task definition

Now time to configure the networking details for the service

Choose networking details (to be continued…)

No we need to attach the service to a load balancer, but we need to create the load balancer and target groups first’

Create a target group (to be attached to a load balancer)

Fill the details

Dont register and targets and create target group

Go to load balancer

Choose the target group and create a load balancer

Important — Delete the default listener from the load balancer

Now go back to configure networking in the Create Service section

Setup Autoscaling

Done. You will see your task/API provisioning/pending and the app will start in some time

Within some time you will see the app running

To find your load balancer go to your service

Click the target group 

Go to your load balancer

Copy the DNS name and paste it in the browser

Now you can see the APP running

If you want to see the IP of your load balancer, copy the load balancer name go to network interfaces and search with the name and you will find your load balancer IP

Read next