How to set up ECR in AWS

Prasanna Nayak
3 min readJul 10, 2021

--

What is ECR ?

Basically ECR is used as a image registry in AWS. How we store images in DockerHub and uses according to our requirements. Same thing ECR does in AWS. It is easy to store, manage, share, and deploy your container images and artifacts anywhere. You need to set your username and password in it.

Steps:-

  1. Create the EC2 instance with docker installed.
  2. Create a ECR repository.
  3. Create a IAM role with AmazonEC2ContainerFullAccess then assign to the EC2 instance.
  4. Log in your aws ECR to your intsance using awscli.
  5. Clone the git repository containing dockerfile and your code.
  1. Create the EC2 instance with docker installed.
  • Launch your EC2 instance
  • Install docker

Once connected, use yum configuration manager to install Docker, by typing the following commands:

# yum update -y

# yum install -y docker

  • Next, start the docker service

# docker service start

2. Create ECR repository

  • Go to aws console and search for ECR
  • Click on create repository.
  • Enter name for your repository
  • Once repo is created, choose the repo and click on view push commands.

3. Create a IAM role with AmazonEC2ContainerFullAccess then assign to the EC2 instance.

Go to aws console, IAM , click on roles, create a role with policy AmazonEC2ContainerFullAccess

  • Then assign this role to EC2 Instance
  • Go to AWS console, click on EC2, select EC2 instance, Go to Actions → Security → Modify IAM role.

4. Log in your aws ECR to your intsance using awscli.

Type the following command in awscli.

aws ecr get-login-password — region ap-south-1 | docker login — username AWS — password-stdin 712576170093.dkr.ecr.ap-south-1.amazonaws.com

5. Clone your git repository

git clone [URL] [directory]

6. Build docker image out of dockerfile

docker build -t [dockerfilename] [path]

--

--

Prasanna Nayak
Prasanna Nayak

Written by Prasanna Nayak

AWS Architect and DevOps Engineer

No responses yet