Using ECR

Create ECR Repository for Frontend Image

  1. Search for Elastic Container Registry. Select Create

8.1.1.png

  1. First is to create a repository to store images for the frontend app. In the left panel, choose Repository then Create repository

8.1.2.png

  • Repository name: fcajresbar-fe.

  • Image tag mutability: select Mutable.

  • Encryption configuration: leave it as default.

  • Click Create to create

8.1.2.png 8.1.3.png

  1. Image for the frontend app created successfully. 8.1.4.png

Create ECR Repository for Backend Image

Similarly, now we will create for Backend Image. With the following information:

  • Repository name: fcajresbar-be.

  • Image tag mutability: select Mutable.

  • Encryption configuration: leave it as default.

  • Click Create to create

8.1.5.png 8.1.5.png 8.1.5.png

We need to create each repository for each different application to manage the version of Docker images more easily, especially for future CI/CD implementation.

Install AWS CLI

  1. First we need to download unzip first.
sudo apt install unzip

8.1.8.png

  1. Then we will use the commands below to install AWS CLI.
sudo curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo unzip awscliv2.zip
sudo ./aws/install

8.1.8.png

  1. After installation, we can check the version to confirm that AWS CLI is installed successfully.
aws --version

8.1.8.png

Push Frontend Image to ECR

  1. Re-enter ECR Console
  • Select fcajresbar-fe
  • Press View push commands

8.1.13.png

  1. A dialog box will pop up and we can see a series of commands.

8.1/14.png

  1. Back to EC2 Instance, we need to use Root User to be able to log in to ECR with Docker.

Because when a user uses sudo to log in to ECR with Docker, the credential is saved in the HOME Dir of that user. But when you execute the push or pull command, it will see the credential in Root instead of in HOME Dir which was saved when logging in before.

  1. In AWS Console of push commands for fcajresbar-fe, run the following command to authenticate and log in to Amazon ECR from your local Docker environment. Before proceeding, ensure you have configured your AWS CLI default profile

8.1/15.png

  1. List all available Docker images on your local machine
docker image ls

8.1/15.png

  1. In the AWS console of push commands for fcajresbar-fe:
  • Run the first command to retrieve an authentication token and authenticate your Docker client with your registry using the AWS CLI 8.1/16.png

  • You can skip the second command as your frontend image is already built

  • Run the third command to tag your image. Replace the placeholder with the image name you created earlier. Once the build is complete, tagging your image allows you to push it to the repository:

docker tag <source_image>: <account_id>.dkr.ecr..amazonaws.com/<repository_name>:

8.1/16.png

  • Run the fourth command to push the image to your newly created AWS repository 8.1/16.png

Push Backend Image to ECR

  1. Similarly, we will also view the push command of fcajresbar-be, remember to copy the login command.

8.1/18.png

  1. Copy and run the login command (the first command) again to ensure your session is active.

8.1/19/png

Apply the appropriate tag to your backend image using the following format:

docker tag <source_image>: <account_id>.dkr.ecr..amazonaws.com/<repository_name>:

8.1/20.png

  1. Finally, execute the push command to upload your backend image to ECR.

8.1/21.png

Check the result

If successful, go to ECR Console, go to each repositories in turn, we can see the result here. 8.1/22.png 8.1/23.png