Push Docker Image EC2 to AWS ECR Repo. #aws #AWS ECR #AwsDevops
Introduction:
Embark on a journey to unravel AWS ECR, the container registry powerhouse, and its key distinctions.
ECR vs Docker Hub: The Showdown
Discover the nuances between AWS ECR and Docker Hub, their strengths, and considerations for your container management needs. Dive into the realm of container registries and their functionalities.
- Create Ec2 Instance, Install AWS CLI and Docker
2. Install AWS cli below commads or gothrough AWS Documentation
before that install zip
sudo apt install unzip
curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o “awscliv2.zip”
unzip awscliv2.zip
sudo ./aws/install
after installation configure aws account
aws configure — then it asking your access key and secret key of aws account
Steps to get the access key and secret key:
goto->aws account -> security credentials
under the page click on create Acces Key
Download the file and save access key and secret key — using this you can configure aws account for your linux or local machine
After adding above things your aws account configure successfully done.
run the command aws — version
3. Docker installation follow the below page
Check docker install or not
sudo docker — version
sudo systemctl statis docker — it fetch docker is running or not
Below mentioned steps for Creating the ECR Repo
Private Repositories and IAM Integration
Learn how ECR’s default private repository setup contrasts with Docker Hub, and explore the seamless integration with IAM users, enhancing security and control. Real-world implications and benefits showcased.
4. Created ECR Private Repo below configration
Clickon the created ECR Repo and click view push commands
It dispaly the list of commands using these you can push your image to ECR
aws ecr get-login-password — region <your-region> | docker login — username AWS — password-stdin <your-aws-account-id>.dkr.ecr.<your-region>.amazonaws.com
5. Created Docker file and build the image below sample docker file script — install apache server and expose the 80 port
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 World!' > /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
Build the docker image
docker build -t <your-image-name> <path-to-dockerfile>
Example command:
Sudo docker build -t <ECR Repo Name> .
then check docker image build or not
sudo docker images
5. After the build completes, tag your image so you can push the image to this repository:
docker tag <your-image-name>:<tag> <your-aws-account-id>.dkr.ecr.<your-region>.amazonaws.com/<your-repository-name>:<tag>
Example Command:
docker tag sureshpecrrepo1:latest 905418395708.dkr.ecr.ap-south-1.amazonaws.com/sureshpecrrepo1:latest
5. Run the following command to push this image to your newly created AWS repository:
Example command:
docker push 905418395708.dkr.ecr.ap-south-1.amazonaws.com/sureshpecrrepo1:latest
Format of the command:
docker push <your-aws-account-id>.dkr.ecr.<your-region>.amazonaws.com/<your-repository-name>:<tag>
then check ECR Repo Image to Push to EC2 TO ECR
Seamless AWS Integration and User Management
Delve into the effortless integration of ECR with AWS services like EKS, ECS, and Fargate, and the time-saving IAM user management it offers. Unveil the operational ease brought by ECR’s AWS compatibility.
Security Features and Best Practices
Uncover the robust security features of AWS ECR, including automated image scanning, tag immutability, and repository customization. Understand the significance of security scanning and image management.
Optimizing Docker Image Deployment with AWS ECR
Master the art of pushing images to AWS ECR efficiently using AWS CLI commands and ensuring seamless container registry access. Real-world scenarios outlined for smooth transition and operational efficiency.
Conclusion:
AWS ECR emerges as a powerful and user-friendly container registry, offering enhanced security, seamless AWS integration, and simplified management. Embrace this tool to level up your container management game.