AWSでほんの少しコンテナに入門してみた – 2


この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので十分ご注意ください。

やったこと

・リポジトリの作成
既存ブログで作成したDockerイメージをECRにプッシュ
・プッシュ後の確認
・リポジトリの削除

前提条件

・EC2は既に作成済み&起動済み
・Dockerはインストール済み
・Dockerイメージ作成済み

1. イメージをECRにプッシュ

イメージプッシュの前に、公式ドキュメントの手順に従いECRを作成します

1-1. イメージ保存するECRリポジトリを作成

–repository-name:作成したいリポジトリ名
–region:リージョン (ex,us-east-1)

aws ecr create-repository --repository-name hello-repository --region ap-southeast-1

怒られました

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

怒られたので aws configure でプロファイルの設定をします

[ec2-user@ip-10-0-1-154 ~]$ aws configure --profile container-test
AWS Access Key ID [None]: QWERTYUIOPASDFGHJKL
AWS Secret Access Key [None]: ngaSOAUFNpeNOLAIurpEFNKN+OWMKO+AFE+c
Default region name [None]: xx-xxxxxxx-x
Default output format [None]: json
[ec2-user@ip-10-0-1-154 ~]$

気を取り直してECRリポジトリを作成

aws ecr create-repository --repository-name hello-repository --region region --profile container-test

repositoryUriの出力結果を確認

{
    "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"
    }
}

repositoryUriでイメージにタグ付け
→ エラーなく実行され、プロンプトが返ってくればOK!

docker tag hello-world aws_account_id.dkr.ecr.region.amazonaws.com/hello-repository

aws ecr get-login-password コマンド実行
レジストリURIを指定

aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com

通りました!

Login Succeeded

1-2. イメージをプッシュ

repositoryUriを使用しイメージをプッシュ

docker push aws_account_id.dkr.ecr.region.amazonaws.com/hello-repository

1-3. プッシュしたイメージの確認

aws ecr list-images --repository-name hello-repository --region region --profile profile-name

1-4. 作成内容の削除

プッシュできることまで確認できたのでとりあえず削除しておきます

aws ecr delete-repository --repository-name hello-repository --region region --force --profile profile-name

参考URL

AWS CLIのプロファイル切り替え方法

AWS公式:AWS Fargate とは
AWS公式:Amazon ECRとは

AWS公式:イメージを Amazon Elastic Container Registry にプッシュする

AWS公式:Amazon ECS における Docker の基本
AWS公式:AWS CLIでのAmazon ECRの使用

AWS公式:Fargate で実行されている Amazon ECS コンテナまたはタスクに Amazon EFS ファイルシステムをマウントする方法を教えてください。

AWS公式:EC2 インスタンスで AWS CLI コマンドを実行できないのはなぜですか?

AWS公式:設定の基本

AWS公式:設定ファイルと認証情報ファイルの設定

AWS公式:プライベートレジストリの認証

Last modified: 2024-02-06

Author