Register your own Docker image with ECR using AWS CLI

Thing you want to do

Push a locally created Docker image to ECR using the AWS CLI

Premise

· AWS CLI version 2 ・ Docker image created

Registration procedure

Here's a summary of Pushing images to Amazon Elastic Container Registry It is what I did. There were times when I couldn't pass the command, so I've written about it.

Preparation

--Access key ID --Secret access key --AWS Region --Output format

It is recommended to specify --profile as shown below when configuring. Here, I named it prf-name.

aws configure --profile prf-name

If you set this, when you use the aws command, if you specify the setting information created with --profile like the following, you can easily tell the command where you want to access. is.

aws s3 ls --profile prf-name

If you do not specify --profile, you will not be able to specify the authentication information as shown below, so be careful with aws configure first.

Unable to locate credentials. You can configure credentials by running "aws configure"

If you want to check the list of created profiles, execute the following. This is convenient when you forget the name you set.

aws configure list-profiles

Create an Amazon ECR repository

aws ecr create-repository --repository-name your-repository-name --region region --profile prf-name

your-repository-name: Favorite repository name region: Region (eg ap-northeast-1)

There is no description on the official website, but if you do not describe --profile, the authentication error message mentioned earlier will be displayed.

Tag the image and push it to Amazon ECR

    1. Create an Amazon ECR repository
aws ecr create-repository --repository-name hello-repository --region region

hello-repository: repository name region: Region (eg ap-northeast-1) output:

{
    "repository": {
        "registryId": "aws_account_id",
        "repositoryName": "hello-repository",
        "repositoryArn": "arn:aws:ecr:region:aws_account_id:repository/hello-repository",
        "createdAt": 1505337806.0,
        "repositoryUri": "aws_account_id.dkr.ecr.region.amazonaws.com/hello-repository"
    }
}
    1. Tag the hello-world image with the value of repositoryUri from the previous step.
docker tag hello-world aws_account_id.dkr.ecr.region.amazonaws.com/hello-repository
    1. Run the aws ecr get-login-password command
aws ecr get-login-password --profile prf-name | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com

output:

Login Succeeded
  1. Push the image to Amazon ECR using the value repositoryUri from the previous step.
docker push aws_account_id.dkr.ecr.region.amazonaws.com/hello-repository
  1. Confirmation of pushed image Check the pushed images using list-images
aws ecr list-images --repository-name hello-repository --region region --profile prf-name

Recommended Posts

Register your own Docker image with ECR using AWS CLI
Proxy server with squid using docker image
How to give your image to someone with docker
Java: Start WAS with Docker and deploy your own application
Using PlantUml with Honkit [Docker]
Build apache7.4 + mysql8 environment with Docker (with initial data) (your own memo)
Create an app catalog site using CLI for Microsoft 365 with Docker
Image Spring Boot app using jib-maven-plugin and start it with Docker
Run (provisionally) a Docker image with ShellCommandActivity on AWS Data Pipeline
Run lambda with custom docker image
Make your own sampler with JMeter
Run the AWS CLI on Docker
Using Java with AWS Lambda-Eclipse Preparation
2. Create Docker image and register Registry
Restart apache with docker php-apache image
Use cuda11.0 with pytorch using Docker
Avoid the error "You have reached your pull rate limit" during docker pull on AWS CodeBuild using AWS ECR
Clone your own web app on GitLab when building a Docker image
[AWS CLI] Switch roles to get a Docker image in another account
Using Java with AWS Lambda-Implementation-Check CloudWatch Arguments
Using Java with AWS Lambda-Implementation-Stop / Launch EC2
[AWS ECR] Save and get Docker images
Create your own validator with Bean Validation
I tried using Scalar DL with Docker
Allow image posting with [Docker + WordPress + MySQL]
Image flew when updating Docker with WSL2
GPU recognition with docker using WSL2 (August 2020)
Deploy your application with VPC + EC2 + Docker.
Try using Kong + Konga with Docker Compose.
Build an environment with Docker on AWS
POST image with multipart / form-data using Moya
Test, build, and push your Docker image to GitHub Container Registry using GitHub Actions
A quick note on using jshell with the official Docker image of the JDK