Monday, January 24, 2022

How to Create Repository In AWS ECR and Push The Docker Image On It

Below Topics Will Cover........

1) AWS EC2 Machine Creation
- Install docker on aws linux machine 2 
- Create docker image 

2) Create IAM User With Programmatic Access 
- Attach Polices (EC2, ECR, ECS)

3) Configure AWS-CLI in Linux Machine 

4) Create ECR Repository And Push the Docker Image 



AWS ECR - Elastic Container Registry is a fully managed container registry that makes it easy to store, manage, share, and deploy your container images and artifacts anywhere.

AWS ECS - Elastic Container Service  makes it easy to deploy, manage, and scale Docker containers running applications, services, and batch processes. 

Amazon ECS places containers across your cluster based on your resource needs and is integrated with familiar features like Elastic Load Balancing, EC2 security groups, EBS volumes and IAM roles.


Step 1) AWS EC2 Machine Creation 

- Install docker on aws linux machine 2 

sudo yum update -y
sudo amazon-linux-extras install docker
sudo yum install docker
sudo service docker start
sudo usermod -a -G docker ec2-user


- Make Dockerfile And Update Below Content (vim Dockerfile)

FROM ubuntu:18.04

# Install dependencies

RUN apt-get update && \
 apt-get -y install apache2

# Install apache and write hello world message

RUN echo 'Hello Tech2Towards!' > /var/www/html/index.html

# Configure apache

RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \
echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \
echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \
echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \
chmod 755 /root/run_apache.sh

EXPOSE 80

CMD /root/run_apache.sh


- Create Docker Image Via Dockerfile

$ docker build -t web-server . 

- Find Created Docker Image  

$ docker images

- Make Container Via Image And Verify Image Working Properly Or Not

$ docker run -t -id -p 80:80 web-server


Step 2) Create IAM User With Programmatic Access 

- Attach Polices (EC2, ECR, ECS)

ECR : AmazonEC2ContainerRegistryFullAccess
EC2 : AmazonEC2FullAccess
ECS : AmazonECS_FullAccess

- Keep Access key ID:Secret access key for Next Step


Step 3) Configure AWS-CLI in Linux Machine 

$ aws configure


Step 4) Create ECR Repository And Push the Docker Image 

- Change --repository-name and --region

$ aws ecr create-repository --repository-name lamp-repository --region ap-south-1


- Tagging A Repository and Change aws_account_number, Repository Name.

$ docker tag web-server aws_account_number_here.dkr.ecr.ap-south-1.amazonaws.com/lamp-repository:v1


- Login Into Docker Client Registry

aws ecr get-login-password | docker login --username AWS --password-stdin aws_account_number_here.dkr.ecr.ap-south-1.amazonaws.com/lamp-repository



- Push Docker Image To ECR

$ docker push aws_account_number_here.dkr.ecr.ap-south-1.amazonaws.com/lamp-repository:v1



- Verify Image pushed in ECR Or Not


No comments:

Post a Comment

testing