We will create 2 different repositories to store Docker Images. First is to create a repository to store images for the frontend app.
Repository name: fcjresbar-fe
.
Image tag mutability: select Mutable.
Encryption configuration: leave it as default.
Similarly, now we will create for Backend Image
With the following information:
Repository name: fcjresbar-be
.
Image tag mutability: select Mutable.
Encryption configuration: leave it as default.
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.
By default (10/15/2024), AWS CLI is not installed by default in Ubuntu.
First we need to download unzip first.
sudo apt install unzip
Then we will use the commands below to install AWS CLI.
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Re-enter ECR Console
fcjresbar-fe
A dialog box will pop up and we can see a series of commands.
Back to EC2 Instance, we need to use Root User to be able to log in to ECR with Docker.
In AWS console of Push commands for fcjresbar-fe
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.
In the previous sections, we have created Images for each application, so now we just need to re-tag them appropriately and push them to the corresponding Registry.
docker image ls
In the AWS console of Push commands for fcjresbar-fe
General format <Account_ID>.dkr.ecr.<region>.amazonaws.com/<Repository_Name>:<Name_tag>
After creating, push the Image to ECR
In the AWS console of Push commands for fcjresbar-fe
Similarly, we will also view the push command of fcjresbar-be
, remember to copy the login command. But logout first
Log back in with the copied login command
Similarly, tag the image appropriately
Push the image to ECR
If successful, go to ECR Console, go to each repositories in turn, we can see the result here.