構築手順
タスク定義
- [Elastic Container Service]-[タスク定義]-[新しいタスク定義の作成]-[EC2]
- タスク定義名:httpd-task
- コンテナの定義
- [Elastic Container Service]-[クラスター]-[クラスターの作成]-[EC2 Linux + ネットワーキング]
- クラスター名: httpd-cluster
- インスタンス数: 2
- キーペア: 既存のキーペアを設定
- ネットワーキング
- VPC: 既存のVPCを選択
- サブネット: 既存のサブネットを選択
- セキュリティグループ: 既存のセキュリティグループを選択
- コンテナインスタンスの IAM ロール: ecsInstanceRole
サービス作成
- [Elastic Container Service]-[クラスター]で httpd-cluster をクリック
- サービス名: httpd-service
- タスクの数:4
セキュリティグループの設定
- ssh(22)、http(80) でのアクセスを許可する
テスト
- ブラウザでアクセスし"It works!"と表示されることを確認する。
- ssh で EC2 にログインする
$ ssh -i ~/mykey.pem ec2-user@ec2-**-**-***-***.ap-northeast-1.compute.amazonaws.com
[ec2-user@ip-***-**-**-*** ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 2a7d646dbba8 11 days ago 177MB
amazon/amazon-ecs-agent latest 622111e45fde 8 weeks ago 29.4MB
amazon/amazon-ecs-pause 0.1.0 b875fd8f097a 8 weeks ago 963kB
[ec2-user@ip-***-**-**-*** ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
256573641bb8 httpd "httpd-foreground" 33 minutes ago Up 33 minutes 0.0.0.0:80->80/tcp ecs-httpd-task-1-httpd-container-80b2d8e5a69893885300
978a01c35740 amazon/amazon-ecs-agent:latest "/agent" 36 minutes ago Up 36 minutes ecs-agent
$ docker version
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
Built: Tue Apr 3 23:37:44 2018
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.4
Git commit: 7390fc6/17.12.1-ce
Built: Tue Apr 3 23:38:52 2018
OS/Arch: linux/amd64
Experimental: false
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 2a7d646dbba8 11 days ago 177MB
amazon/amazon-ecs-agent latest 622111e45fde 8 weeks ago 29.4MB
amazon/amazon-ecs-pause 0.1.0 b875fd8f097a 8 weeks ago 963kB
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
256573641bb8 httpd "httpd-foreground" About an hour ago Exited (0) 2 minutes ago ecs-httpd-task-1-httpd-container-80b2d8e5a69893885300
978a01c35740 amazon/amazon-ecs-agent:latest "/agent" About an hour ago Up About an hour ecs-agent
$ docker top 621192cdd629
UID PID PPID C STIME TTY TIME CMD
root 4189 4169 0 06:30 ? 00:00:00 httpd -DFOREGROUND
bin 4241 4189 0 06:30 ? 00:00:00 httpd -DFOREGROUND
bin 4242 4189 0 06:30 ? 00:00:00 httpd -DFOREGROUND
bin 4243 4189 0 06:30 ? 00:00:00 httpd -DFOREGROUND
$ docker logs 256573641bb8
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sun Jul 08 05:41:32.048832 2018] [mpm_event:notice] [pid 1:tid 139972016797568] AH00489: Apache/2.4.33 (Unix) configured -- resuming normal operations
[Sun Jul 08 05:41:32.049183 2018] [core:notice] [pid 1:tid 139972016797568] AH00094: Command line: 'httpd -D FOREGROUND'
27.0.3.145 - - [08/Jul/2018:05:42:57 +0000] "GET / HTTP/1.1" 200 45
27.0.3.145 - - [08/Jul/2018:05:42:57 +0000] "GET /favicon.ico HTTP/1.1" 404 209
[Sun Jul 08 06:25:00.715569 2018] [mpm_event:notice] [pid 1:tid 139972016797568] AH00491: caught SIGTERM, shutting down