26
[email protected] 1 Create ECR, Install Docker, Create Image, and Push Image To ECR [Edition 06] [Last Update 201121] For any issues/help contact : [email protected]

AG08 Pushing Image to ECR

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

[email protected] 1

Create ECR, Install Docker,

Create Image, and

Push Image To ECR

[Edition 06]

[Last Update 201121]

For any issues/help contact : [email protected]

[email protected] 2

Contents

1 Introduction .........................................................................................................................................................3

2 Documentation Links ........................................................................................................................................5

3 Pre-Requsite .........................................................................................................................................................6

4 Creating Repository in ECR .............................................................................................................................7

5 Install Docker & Create Image .................................................................................................................... 11 5.1 Installing Docker On EC2 Instance...................................................................................................................... 11 5.2 Creating a Docker File and build Image from it ............................................................................................. 13

6 Push Docker Image to ECR ........................................................................................................................... 18

7 Deleting/cleanup ............................................................................................................................................. 23 7.1 Delete the pushed image and ECR ....................................................................................................................... 23

8 Summary............................................................................................................................................................. 26

[email protected] 3

1 INTRODUCTION

ECR: Amazon Elastic Container Registry (ECR) is a fully managed Docker container registry

that makes it easy for developers to store, manage, and deploy Docker container images.

Amazon ECR is integrated with Amazon Elastic Container Service (ECS), simplifying your

development to production workflow. Amazon ECR eliminates the need to operate your own

container repositories or worry about scaling the underlying infrastructure.

Amazon ECR hosts your images in a highly available and scalable architecture, allowing you to

reliably deploy containers for your applications.

Integration with AWS Identity and Access Management (IAM) provides resource-level control of

each repository. With Amazon ECR, there are no upfront fees or commitments. You pay only

for the amount of data you store in your repositories and data transferred to the Internet.

This activity guide cover steps for:

1. Pushing Images to Amazon ECR

a. Creating a Repository in ECR

b. Configure AWS credentials and Install Docker

c. Creating a Dockerfile and build Images from it

d. Pushing images to Repository

2. Deleting/Cleanup

[email protected] 4

a. Terminating the Instance

b. Deleting the pushed image and Repository

[email protected] 5

2 DOCUMENTATION LINKS

1. Create Repository using AWS Console https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-create.html

2. Create Repository using CLI

https://docs.aws.amazon.com/cli/latest/reference/ecr/create-repository.html

3. Amazon ECR

https://aws.amazon.com/ecr/

4. Amazon ECR FAQ’s

https://aws.amazon.com/ecr/faqs/

5. Docker basics for Amazon ECS and ECR

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html

[email protected] 6

3 PRE-REQUSITE

• Note: Create account (Trial or Paid) on AWS Cloud.

Follow Activity Guide Register_for_AWS_Free_Tier_Account_And_Login_to_AWS Console_ed** from portal

• Note: In this guide we are going using Linux machine to perfrom this lab you can provision Linux machine on Amazon.

Follow Activity Guide Create_&_Connect_To_EC2_Linux_Instance_ed** from Portal to create Linux machine on AWS.

• Note: To install & configure AWS CLI, and to install EKSCTL and kubectl.

Follow guide Activity Guide: AG_Install_Configure_AWSCLI_KUBECTL_EKSCTL_on_Linux_ed** from Portal

[email protected] 7

4 CREATING REPOSITORY IN ECR

1. Open your Console and search ECR.

2. Click on Create Repository.

[email protected] 8

3. Enter your repository name and click on Create Repository.

[email protected] 9

4. Repository Created Successfully.

[email protected] 11

5 INSTALL DOCKER & CREATE IMAGE

5.1 Installing Docker On EC2 Instance

1. Login to Linux (Ubuntu) machine that you created following and Install & Configure AWSCLI Using Guide: AG_Install_and_Configure_AWSCLI_Kubectl_and_EKSCTL_on_Linux_ed1** from Portal.

2. Switch to the root user

sudo su -

3. First Update Software Repositories

$ sudo apt-get update -y

4. Install Docker

$ sudo apt install docker.io

Note: If you get message like below then type Y and hit enter

[email protected] 12

5. Start and Enable Docker

$ sudo systemctl start docker

$ sudo systemctl enable docker

6. Check Docker status

$ sudo systemctl status docker

You should see output like below (exit by typing q)

7. Check Docker Version

docker –version

You should see output like

[email protected] 13

5.2 Creating a Docker File and build Image from it

1. Create a Dockerfile.

[email protected] 14

2. Dockerfile Created.

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

[email protected] 15

3. Now build the docker image from the Dockerfile.

docker build -t hello-world .

[email protected] 17

4. Validate docker images created.

docker images

[email protected] 18

6 PUSH DOCKER IMAGE TO ECR

1. Access ECR console and click on View push commands

[email protected] 19

Note: If you get error like “Unable to locate credentials. You can configure credentials by running "aws configure". Error: Cannot perform an interactive login from a non TTY device” then make sure you follow “aws configure” from guide AG_Install_and_Configure_AWSCLI_Kubectl_and_EKSCTL_on_Linux_ed1** from Portal.

[email protected] 20

2. Copy the get-login password command and run as well copy other commands and paste.

3. Run the docker push command that you copied, and the image will start uploading to ECR

repository. First tag your image with the Amazon ECR registry, repository, and image tag name combination to use.

[email protected] 21

Note: The registry format is aws_account_id.dkr.ecr.region.amazonaws.com. The repository name should match the repository that you created for your image.

docker tag <Image_Name>:<image tag> <aws_account_id>.dkr.ecr.<region>.amazonaws.com/<repository>:<tag>

docker tag hello-world:latest 111167273292.dkr.ecr.us-east-1.amazonaws.com/ecr-demo:latest

Second Step is to push image to ECR. To push Image

docker push <aws_account_id>.dkr.ecr.<region>.amazonaws.com //<repository>:<tag>

docker push 111167273292.dkr.ecr.us-east-1.amazonaws.com/ecr-demo:latest

[email protected] 22

4. Back on ECR console your image will be successfully pushed to Repository.

[email protected] 23

7 DELETING/CLEANUP

7.1 Delete the pushed image and ECR

1. Back on ECR console delete the pushed image at first.

2. Type delete and Click on Delete.

[email protected] 24

3. Select your Repository and delete it by clicking on delete.

4. Click on Delete.

[email protected] 26

8 SUMMARY

This activity guide covered steps to:

1. Pushing Images to Amazon ECR

a. Creating a Repository in ECR

b. Configure AWS credentials and Install Docker

c. Creating a Dockerfile and build Images from it

d. Pushing images to Repository

2. Deleting/Cleanup

a. Terminating the Instance

b. Deleting the pushed image and Repository