How to push an image to ECR

Firstly, create an ECR repository. Later you can build the container and push the image to the already created repository.
How to create an ECR Repository
Amazon Elastic Container Registry (ECR) is a fully managed Docker container registry service provided by Amazon Web Services (AWS). This service allows you to easily store, manage, and deploy Docker container images.
Login to the AWS account, Create an ECR Repository.


Ensure the registry is private, so that the repository images are safe.
You may:
- Enable Tag immutability
- Enable Scan on Push
- Encryption

Build and push Image to ECR
- Authorize docker to push images to the ECR repository that we created
aws ecr get-login-password --region <region_name> | docker login --username AWS --password-stdin <ECR name>
- Build your docker image
docker build -t <container_name>:<tag> .
docker tag <container_name>:<tag> <ECR>/<reponame>:<tag>
- Push the image to the ECR
docker push <ECR>/<reponame>:<tag>
- Once you push the image, the image tag must be visible in the ECR repo

Now the image is ready to be deployed.