LoginSignup
0
0

More than 1 year has passed since last update.

ECSのFargateを使用してログでHello-Worldを表示させてみた。

Last updated at Posted at 2021-11-22

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を開いてタスク定義へ移ります。タスク定義の作成を押してください。
スクリーンショット 2021-10-08 17.11.02.png

起動タイプの互換性の選択で「Fargate」を選択してください。
次へ!
タスク定義は自分で確認できるものを入力してください。
スクリーンショット 2021-10-08 17.13.35.png
タスクメモリ(GB)とタスクCPU(vCPU)もそれぞれ入力します。
コンテナ追加を押してください。
スクリーンショット 2021-10-08 17.14.33.png
〜コンテナ追加〜
コンテナ名は自分で確認できるもの、イメージはさっき動かした「hello-world」でお願いします。
スクリーンショット 2021-10-08 17.18.31.png

これで作成してください。

3. クラスターの作成

クラスターの作成を押してください
スクリーンショット 2021-10-08 17.22.10.png

クラスターテンプレートの選択は「ネットワーキングのみ」を押してください。
次へ!
クラスター名を入力し、VPCの作成にチェックを入れてください。(CIDRブロックとサブネットが作成されます。)
スクリーンショット 2021-10-08 17.23.48.png

もしも、VPCの数が上限を超える場合、作成されないのでVPCの確認が必要です。

4. タスクを実行し、ログでHello-Worldを表示

作成したタスクにチェックを入れ、アクションからタスクの事項をします。
スクリーンショット 2021-10-08 17.33.46.png

起動タイプを FARGATE、クラスターを作成したもの、クラスターVPCとサブネットは作成したものを選択します。

入力する3項目
・起動タイプ
・クラスター
・クラスターVPC
・サブネット

入力が終わりましたら「タスクの実行」を押して実行します。
実行したものがクラスターのタスクに表示され、ステータスがRunning、のちにStoppedとなります。
動作が終了しましたら、タスクを開いてログを確認してみてください。
スクリーンショット 2021-10-08 17.45.39.png
こんな感じでログが出せましたら完了です!

参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0