To create the Repo in ECR and push/pull the image to the same

Step1 : Creating the Repository

Go to the console -> ECR -> create a Repository

image

Now, create a private repository, name your repository and click on create.

image

Our Private Repository has been created.

image

Step2 : Creating our own Image.

Launch an EC2 instance and SSH into it and install Docker in the instance.

sudo yum update
sudo yum search docker
sudo yum info docker
sudo yum install docker
sudo systemctl enable docker 

Now, docker is installed , we will create the image now

mkdir shruti
cd shruti
vim Dockerfile

image

write this content in the Dockerfile

Now to run and build the image , use the following commands

docker build -t awsimage1:v1 .
docker run -dit awsimage1:v1

check the image and the running containers by these commands, respectively
docker images
docker ps

image

Our Image is now created

Step3 : Push the Image to the ECR Repo

Go to the Repo that we have created in step1 and click on the "view push commands".

image

Now configure aws-cli to get the password for login into the repository.

aws configure
Access Key ID [None]: Access Key 
AWS Secret Access Key [None]: Secret Key 
Default region name [None]: 
Default output format [None]: 

It will ask for username and password configure your aws-cli and type this command to get the password

image

Take the repo ID and Login using the command with username and password

image

Rename your image to the repo name

docker tag awsimage1:latest 655645242246.dkr.ecr.ap-south-1.amazonaws.com/shruti-test1:latest

And, push into the Repository

docker push 655645242246.dkr.ecr.ap-south-1.amazonaws.com/shruti-test1:latest

Now, our image has been pushed into the repository

Go to the ECR -> Repositories ->

image

And, we can pull the Image using the command

docker pull 655645242246.dkr.ecr.ap-south-1.amazonaws.com/shruti-test1:latest