AWS Elastic Container Registry
While Docker is widely used on in software world these days, AWS caught up with the trend by providing a Container Registry Service that allows us to create, delete, and put versions on designated images. AWS Elastic Container Registry service aims to provide a repository of images to facilitate AWS Elastic Container Service (ECS). To work with Elastic Container Registry service, there are few command line instructions to be familiarized with.
Elastic Container Repository Creation
We need to first create a repository on ECR, much like the concept of using github. Elastic Container Repository can be created using aws cli and console.
Create repository using AWS Console
Create repository using aws cli
Before using aws cli to create elastic container repository, you need to set up credential file.
aws ecr create-repository --repository-name name-of-your-project
Authenticate
After ecr repository is created, you need retrieve login information to grant docker privilege to access ecr. You will need to install docker application before continue on this step. Docker community has a really straight-forward documentation for docker installation, click here for more information on docker installation details.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.us-east-1.amazonaws.com
Build
A docker image has to be built before everything else. It is simple
docker build -t docker_image_name .
Tag
Tag newly created docker image with the name matches name of elastic container repository created earlier.
docker tag docker_image_name:latest aws_account_id.dkr.ecr.us-east-1.amazonaws.com/name_of_ecr_container_name:ecr_image_tag
Push
If image tag is set properly, i.e. image tag has to be matched to the name of elastic container repository on AWS, you can now push this image to aws. If the push is successful, you will be able to observe this version on AWS console.
docker push aws_account_id.dkr.ecr.us-east-1.amazonaws.com/name_of_ecr_container_name:ecr_image_tag