Here Iam using a website with nginx server to deploy on a container with the help of ECR.
Let’s get the data
git clone https://github.com/anuvindhs/CLOUD-is-AWSome.git
Building a docker file
Lets build our NGINX docker file for our website.
once you have created the docker file inside the folder, copy-paste the below commands
FROM nginx:latest COPY ./ /usr/share/nginx/html/
Make sure you have programmatic access via AWS CLI
Full permissions to ECS & AmazonEC2ContainerRegistryFullAccess
Create a repository
- Goto ECR from AWS console and create a repository
- Create a ECR repo ,i have named mine
Login to ECR
Now using AWS CLI login to ECR
aws ecr get-login-password --region xx-xxxxxx-xx| docker login --username AWS --password-stdin xxxxxxxxxx.dkr.ecr.xx-xxxxxx-xx.amazonaws.com
Build the docker image
docker build -t webapp-ecr-repo .
Lets tag our image with repo name
docker tag webapp-ecr-repo:latest xxxxxxxxx.dkr.ecr.xx-xxxxxx-xx.amazonaws.com/webapp-ecr-repo:latest
Lets push the image to the repository
docker push xxxxxxxxxx.dkr.ecr.xx-xxxxxxx-xx.amazonaws.com/webapp-ecr-repo:latest
if you are using PowerShell on windows please use windows commands to push the image to the repo.
- Goto ECS dashboard and click Create Cluster.
Select the default VPC and Subnets available.
Also enable Auto assign public IP
- you can use default Security group or create a new one or can attach a Security group which is already created.
- Now click Create
- Click on create Task Definition & then select EC2
- I am naming mine as
Add a name, mine is
Copy your ECR repo URI from the repository and update that on the image coloumn
Map your ports, here its 80:80 ,
Select out Task Definition we created.
Select our Cluster
Once the Task is created you will be able to see a Running Status
if you navigate to external Link you will be able to see the live website.
Congratulations, now you have successfully configured a docker image which you have pushed to ECR and Deployed on a container with ECS.