DockerのECSプラグインを使う

ECS PluginはDockerの拡張機能
ECSのFargate上にデプロイすることができる

$ git clone https://github.com/docker/ecs-plugin.git
$ cd ecs-plugin/example/
$ docker build app -t example
$ docker images –filter reference=example
REPOSITORY TAG IMAGE ID CREATED SIZE
example latest 31ac32e7e8dd 18 seconds ago 52.9MB

$ docker run -t -i -p 5000:5000 example

OK(※redisが起動していない為)

### AWS ECS
DockerHubの様なもの
作成したDockerイメージをECRにpushし、docker-compose使用時にpull
$ docker context use default
$ docker context ls

### ECS用のIAM作成
こちらを参考にECSのユーザを作成する
https://docs.aws.amazon.com/ja_jp/AmazonECR/latest/userguide/get-set-up-for-amazon-ecr.html
accound_id, access_key_id, secret_access_keyをメモ

### AWS CLI install
$ dnf install python3-pip
$ pip3 install awscli –upgrade –user
$ aws –version
aws-cli/1.19.28 Python/3.6.8 Linux/4.18.0-193.19.1.el8_2.x86_64 botocore/1.20.2
$ aws configure
-> Administratorのaccess_key_id, secret_access_keyと ap-northeast-1を入力

$ timedatectl set-timezone Asia/Tokyo

$ aws ecr get-login-password –region ap-northeast-1 | docker login –username AWS –password-stdin hoge.dkr.ecr.ap-northeast-1.amazonaws.com
Login Succeeded

// レポジトリ作成
$ aws ecr create-repository \
–repository-name example \
–image-scanning-configuration scanOnPush=true \
–region ap-northeast-1
// タグ付け
$ docker tag example:latest hoge.dkr.ecr.ap-northeast-1.amazonaws.com/example:latest
// imageをpush
$ docker push hoge.dkr.ecr.ap-northeast-1.amazonaws.com/example:latest
$ aws ecr list-images –repository-name example
{
“imageIds”: [
{
“imageDigest”: “sha256:75260261d397dd588f43bd4fc16118cb2763c55c46caa313a9a2caf0202636f9”,
“imageTag”: “latest”
}
]
}

AWS console

イマイチよくわってないが、なんか出来とるな。。。