Deployment of SpringBoot Services on AWS Elastic Container Services: Part 1 AWS ECR (Amazon Elastic Container Registry (ECR)
Create the repository:
- Navigate to the Amazon ECR console.
- On the Repositories page, select Create Repository.
- On the Create repository page, enter the following name for your repository: api.
⚐ Note: Under Tag immutability, leave the default settings. - Select Create repository.
After the repository is created, you receive a confirmation message and the repository address is listed under URI. The repository address is in the following format: [account-ID].dkr.ecr.[region].amazonaws.com/[repo-name]. The [account-ID], [region], and [repo-name] will be specific to your setup.
ECR |
Build and Push Docker Image to ECR
Use the terminal to authenticate Docker log in:
- Run one of the following commands, depending on which version of AWS CLI you have (To identify the version, run aws --version. If needed, configure your credentials.):
- If you have AWS CLI version 1.x, then run:
$(aws ecr get-login --no-include-email --region [your-region])
Replace [your-region], for example: $(aws ecr get-login --no-include-email --region us-west-2) - If you have AWS CLI version 2.x, then run:
aws ecr get-login-password --region [your-region] | docker login --username AWS --password-stdin [your-AWS-account-ID].dkr.ecr.[your-region].amazonaws.com
Replace [your-region] and [your-AWS-account-ID], for example: aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-west-2.amazonaws.com
If authentication is successful, you will receive the confirmation message: Login Succeeded.
- To build the image, run the following command in the terminal:
- After the build completes, tag the image so you can push it to the repository:
docker tag api:latest [account-ID].dkr.ecr.[region].amazonaws.com/api:v1
- Push the image to Amazon ECR by running:
docker push [account-id].dkr.ecr.[region].amazonaws.com/api:v1