1. Docker イメージの準備
Dockerとは、Docker社が開発している、コンテナ型の仮想環境を作成、配布、実行するためのプラットフォームです。
まず、ターミナルにこちらを起動させてください。
docker run hello-world
結果
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
これはDockerにすでにある公式イメージを動かしました。
次はAWSに移ります。
2. AWS ECS タスク定義の作成
ECSを開いてタスク定義へ移ります。タスク定義の作成を押してください。
起動タイプの互換性の選択で「Fargate」を選択してください。
次へ!
タスク定義は自分で確認できるものを入力してください。
タスクメモリ(GB)とタスクCPU(vCPU)もそれぞれ入力します。
コンテナ追加を押してください。
〜コンテナ追加〜
コンテナ名は自分で確認できるもの、イメージはさっき動かした「hello-world」でお願いします。
これで作成してください。
3. クラスターの作成
クラスターテンプレートの選択は「ネットワーキングのみ」を押してください。
次へ!
クラスター名を入力し、VPCの作成にチェックを入れてください。(CIDRブロックとサブネットが作成されます。)
もしも、VPCの数が上限を超える場合、作成されないのでVPCの確認が必要です。
4. タスクを実行し、ログでHello-Worldを表示
作成したタスクにチェックを入れ、アクションからタスクの事項をします。
起動タイプを FARGATE、クラスターを作成したもの、クラスターVPCとサブネットは作成したものを選択します。
入力する3項目
・起動タイプ
・クラスター
・クラスターVPC
・サブネット
入力が終わりましたら「タスクの実行」を押して実行します。
実行したものがクラスターのタスクに表示され、ステータスがRunning、のちにStoppedとなります。
動作が終了しましたら、タスクを開いてログを確認してみてください。
こんな感じでログが出せましたら完了です!
参考記事