Deploying Docker Container on AWS Using ECS And ECR
Introduction:
This project will help to deploy the real world containerized application on AWS using their managed services so that we will not have to manage any server by own, ECS (elastic container service) is AWS managed service which offers you to deploy you containers on ec2 instances (you responsible for scaling, monitoring, patching of server) as well as using fargate (fully managed service). First we will create docker image and push on registry, we will use ECR for docker registry then deploy that image on ECS.
Lets start the practical demonstration!
Below is the link of our application:
https://github.com/piyushgarg-dev/nodejs-docker-example.git
First create the docker image on local system using docker file in the repo:
Then run container on local system:
Now we will push to image to AWS ECR, first create the repo:
Follow the instruction to push the image to this repo:
Now we will go to ECS service for deployment of container using this image:
First we will create new cluster which can have many micro services:
Then we will create task, task is basically knows how to run image inside cluster, all the conf and variables will be in task:
Then we will ask service to get that task and run it. It will make sure scalability and re create if some thing crash etc, we can have multiple task also and one cluster can have multiple services also:
Create new task now:
Also provide image url and port in task:
Also define health check of container:
Now time to create a service that will take conf from task and run it:
First tell the service which task it will run and set the name of service:
Set desire task to 2 so there will load balancer which run two task parallel and divide load:
Now add load balancer:
Now our service is running with two task (container) as we define minimum value to 2:
Now we can access our application through load balancer end point:
Thats all in this project.