DEV Community

kaede
kaede

Posted on

AWS 基礎 Part 11 -- ECR に Spring アプリをデプロイする

前提

  1. ECR への nginx イメージの push と ECS の動作確認はできている
  2. Spring アプリの Docker イメージへのビルドと動作確認はできている。

https://dev.to/kaede_io/ecr-elastic-container-registory-ni-ngnix-no-docker-imeziwo-push-suru-456i

AWS 基礎 Part 02 で ECR に nignx のコンテナをデプロイした。

https://dev.to/kaede_io/kotlin-ji-chu-part-13-spring-apuriwo-docker-imezinibirudositeshi-xing-suru-1a6i

Kotlin 基礎 Part 13 で Spring アプリを Docker コンテナにビルドした。実行して動作確認済み。

今回は Spring アプリを ECR にデプロイする。


ECR push


push 用のイメージの作成

docker build . -t hello-spring --platform linux/amd64 docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-spring latest 39cba615c41c 12 minutes ago 382MB 
Enter fullscreen mode Exit fullscreen mode

hello-spring のイメージ名でビルドする。


push 先のリポジトリを作成

ECR リポジトリ作る

  • 公開設定: private
  • リポジトリ名: hello-spring

これでリポジトリを作成する。


イメージにタグつけする

docker tag hello-spring:latest \ {userId}.dkr.ecr.ap-northeast-1.amazonaws.com/hello-spring:latest docker images {userId}.dkr.ecr.ap-northeast-1.amazonaws.com/hello-spring latest 39cba615c41c 33 minutes ago 382MB 
Enter fullscreen mode Exit fullscreen mode

先ほど作成した hello-spirng のイメージに
{userId}.dkr.ecr.ap-northeast-1.amazonaws.com/
のタグをつける


リポジトリにローカルからログインする

aws ecr get-login-password \ --region \ap-northeast-1 | \ docker login --username AWS --password-stdin \ {userId}.dkr.ecr.ap-northeast-1.amazonaws.com 
Enter fullscreen mode Exit fullscreen mode

これでイメージを ECR に push できるようになった


イメージを ECR に push する

docker push \ {userId}.dkr.ecr.ap-northeast-1.amazonaws.com/hello-spring:latest The push refers to repository [803827238734.dkr.ecr.ap-northeast-1.amazonaws.com/hello-spring] 2da32836aa49: Pushed 2f27ef47a1b3: Pushed a7f0709c283b: Pushed f9e315186df9: Pushed 8e012198eea1: Pushed latest: digest: sha256:ce76782dfcba3524d9a3ba020a700f5798c22ab87ff6d00f8d36768d35a96970 size: 1372 
Enter fullscreen mode Exit fullscreen mode

dokcer push リポジトリ名で push できる


ECR で確認する

Image description

push されて届いているのを確認できた。

Top comments (0)