In this blog, we will deploy a docker container in Amazon ECS(Elastic Container Service) using ECR ( Elastic Container Registry)
Prerequisite
- Configure aws credential
- Install aws cli version 2
- Clone this git repo
- Local workstation ( I am using AWS EC2 instance)
Agenda:
- Create and Push to ECR repository
- Create a ECS cluster
- Create a Task Definition
- Run the task
- Create a Service
Create a ECR repository
Go to AWS > ECR > Create a repository
Click on your repository
View push commands
You will see the below commands to push your docker image to the ECR repository
clone the git repodocker build -t sample_ecs .
docker tag sample_ecs public.ecr.aws/w0f5g4k6/deploy:v7'aws ecr-public get-login-password --region us-east-1 | docker login --username AWS -p $(aws ecr get-login-password --region us-east-1)docker push public.ecr.aws/w0f5g4k6/deploy:v7
Run the image locally to test
docker run -it --rm -d -p 8089:8080 --name samplenginx_c public.ecr.aws/w0f5g4k6/deploy:v7
You should be able to open the url http://localhost:8089/LoginWebApp-1
Create ECS Cluster
These are the four critical items in ECS you need to know: