AWSのECSを構築するその3(ECR作成)
完成予定
今回
今回やること
- ECRの作成
- Dockerfile作成
- dockerビルド、動作確認
- ECRへタグづけ、Push
ECRの作成
「使用方法」を選択
リポジトリパラメータを設定
↓
ポリシーを作成&割り当て
ポリシーを作成を選択
権限を設定
タグ
確認
対応ユーザーにポリシーを付与
↓
Dockerfileを作成&ビルド
Dockerfile作成
Dockerfile
# image FROM nginx:alpine # 設定ファイルをコピー COPY conf.d/default.conf /etc/nginx/conf.d/default.conf # index.html RUN mkdir -p /var/www/htdocs COPY htdocs/index.html /var/www/htdocs/index.html
conf.d/default.conf
server { listen 80; listen [::]:80; server_name localhost; root /var/www/htdocs; index index.html; location / { try_files $uri $uri/ =404; } }
htdocs/index.html
<html> testdata </html>
ビルド
docker build -t mshge1979-frontend .
動作確認
docker run -it -p 8080:80 --rm --name test1 \ mshge1
↓
% curl http://localhost:8080 <html> testdata </html> %
AWS CLIインストール
https://awscli.amazonaws.com/AWSCLIV2.pkg
※AWS CLI バージョン 2 のインストール、更新、アンインストール - AWS Command Line Interface
アクセスキー、シークレットアクセスキー設定
% aws configure AWS Access Key ID [None]: [アクセスキー情報] AWS Secret Access Key [None]: [シークレットアクセスキー情報] Default region name [None]: ap-northeast-1 Default output format [None]: json %
ログイン
% aws ecr get-login-password --profile [プロファイル名] | docker login --username AWS --password-stdin [識別ID].dkr.ecr.ap-northeast-1.amazonaws.com Login Succeeded %
※複数のプロファイルを設定していたらうまく認識されないのでプロファイルを設定した方が上手くいく
ECRのタグづけ
docker tag mshge1979-frontend:latest [識別ID].dkr.ecr.ap-northeast-1.amazonaws.com/mshge1979-frontend:0.0.1
ECRへプッシュ
docker push [識別ID].dkr.ecr.ap-northeast-1.amazonaws.com/mshge1979-frontend:0.0.1
確認
関連記事
m-shige1979.hatenablog.com m-shige1979.hatenablog.com m-shige1979.hatenablog.com m-shige1979.hatenablog.com