In this blog post we are going to discuss on how to deploy your image on AWS ECR, which is managed container service by Amazon Web Services.
Please follow the step to upload your docker image to AWS ECR
Create ECR Repository
Your Repository has been created successfully. Now you have to upload your image in this repository.
Login to AWS ECR
On windows platform, run following command
aws ecr get-login-password --region REGION_NAME | docker login --username AWS --password-stdin 8XXXXXXXXXXXX.dkr.ecr.AWS_REGION.amazonaws.com
make sure to replace REGION_NAME with your region name like ap-south-2
Build your Image
docker build -t REPOSITORY_NAME .
Tag your image to latest
docker tag REPOSITORY_NAME:latest 8XXXXXXXXXXX.dkr.ecr.AWS_REGION.amazonaws.com/REPOSITORY_NAME:latest
Now Push your image to AWS repository
docker push 8XXXXXXXXXXX.dkr.ecr.AWS_REGION.amazonaws.com/REPOSITORY_NAME:latest
Create a script to automate the above process in Windows 10 using PowerShell
Write-Output "=========================== going to deploy changes on SERVER ================================"; aws ecr get-login-password --region AWS_REGION | docker login --username AWS --password-stdin 8XXXXXXXXXXX.dkr.ecr.AWS_REGION.amazonaws.com docker build -t REPOSITORY_NAME . docker tag REPOSITORY_NAME:latest 8XXXXXXXXXXX.dkr.ecr.AWS_REGION.amazonaws.com/REPOSITORY_NAME:latest docker push 8XXXXXXXXXXX.dkr.ecr.AWS_REGION.amazonaws.com/REPOSITORY_NAME:latest Write-Output "==================================== deployment done =========================================";
Please make sure to replace
- AWS_REGION with valid AWS region-name
- 8XXXXXXXXXXX with your account id
- REPOSITORY_NAME with the valid repository name
You have successfully pushed your image to AWS ECR.