paint-brush
Creating an AWS Elastic Container Registry (ECR) Using an EC2 Instance on Ubuntu by@vdoomik
215 reads

Creating an AWS Elastic Container Registry (ECR) Using an EC2 Instance on Ubuntu

by Uladzislau BaryshchykSeptember 1st, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Amazon also has container launch and storage solutions - Elastic Container Registry (ECR) In this article, I will show you how to create your own container, upload it to the repository. For the demonstration, I'll be using an EC2 instance on Ubuntu and run the command: Docker

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Creating an AWS Elastic Container Registry (ECR) Using an EC2 Instance on Ubuntu
Uladzislau Baryshchyk HackerNoon profile picture

Introduction

Docker allows developers to package applications in containers - standardized executable components that combine application source code with the operating system (OS) libraries and dependencies needed to run that code in any environment. Amazon also has container launch and storage solutions - Elastic Container Registry (ECR). In this article, I will show you how to create your own container, upload it to the repository.

Create a Docker Image

First, let's create our own container. For the demonstration, I'll be using an EC2 instance on Ubuntu. The instance must have Docker installed and run the command:


nano DockerFile


For our example, we use the approach httpd on amazon linux. Next, write code (Image 1):


FROM amazonlinux

RUN yum -y update

RUN yum -y install httpd

RUN echo 'Hello World from ECR! This is version 1' > /var/www/html/index.html

CMD ["/usr/sbin/httpd","-D","FOREGROUND"]

EXPOSE 80

Image 1 - Creating a Dockerfile

Next, let's compile the image and run the command:


docker build -t hello-world-app .


Do not forget to write dot after -app. And then check that it is present in our images, run the docker images command (Image 2).


Image 2 - Docker images

As we can see, you have two new images created. This completes the first step.

Creating a repository

The second, let's open the AWS Management Console and then to the ECR service, then go to the Repositories tab and click Create a repository (Image 3).


Image 3 - Creating the repository

Here we need to enter the name of the repository and create a private one. I want to note that Amazon has restrictions on private, public repositories and be careful not to exceed the limit. Next, we will go to the repository, and as we see that it is impossible to upload our image to the repository. Moreover, we do not even have a button. Next, click the View push commands button and see Amazon's commands (Image 4).


Image 4 - Push commands

These commands are for the old version of the CLI, but I will show you how to use a much simpler command. Next, we need to rename our image to the name that AWS suggests to us. Let's copy this freak name (Image 5).


Image 5 - URL of the repository

Next, go to our terminal and run the command:


docker tag hello-world-app:latest  977701475595.dkr.ecr.us-east-1.amazonaws.com/app1:v1


You can see the result in image 6.


Image 6 - Rename the repository

Next, as I described earlier, we will run a command to send our image to the repository. To do this, run the aws configure command and enter the Access key id and Secret access key. Next, we will install the region in which you have deployed the repository (Image 7).


Image 7 - Login on AWS

To push the image, you need to log in by entering the command:


aws ecr get-login --no-include-email --region us-east-1


Then we receive an unusual answer (Image 8). So let's copy it and run it (Image 9).


Image 8 - Login on AWS ECR Image 9 - Login Succeeded

Using the command from View push command:


docker push 977701475595.dkr.ecr.us-east-1.amazonaws.com/app1:v1


Let's send our image to the repository. After that, we can open AWS Management Console and see our container in the ECR service (Image 10).


Image 10 - Our private repository is created

Conclusion


In conclusion, I showed how to create your own Docker container, then place your own container in the Elastic Container Registry. As you can see, this is not as complicated as it might seem at first glance, and now everyone, after reading this article, can do the same.
바카라사이트 바카라사이트 온라인바카라