ECS を利用していて幾つかはまったポイントがあったのでまとめました。
started 1 task が複数回実行されるが、コンテナが起動しない
$ ecs-cli compose service up ... level=info msg="(service hogehoge) has started 1 tasks ..." level=info msg="(service hogehoge) has started 1 tasks ..." level=info msg="(service hogehoge) has started 1 tasks ..."
ecs-cli compose service up でデプロイ時にタスク起動を実行するものの、起動が正しくできていない状態です。
こちらはコンテナ起動時の処理に問題がある場合があります。
already using a port required by your task
service hogehoge was unable to place a task because no container instance met all of its requirements. The closest matching container-instance a1b2c3d4-e5f6-g7h8-j9k0-l1m2n3o4p5q6 is already using a port required by your task
port mapping を以下の様に設定していた。
"portMappings": [ { "hostPort": 0, "protocol": "tcp", "containerPort": 80 } ],
新しいタスクでも 0:80 のポートを利用しようとする為、エラーとなります。 以下の様に設定することで回避できました。
"portMappings": [ { "containerPort": 80 } ],
insufficient memory available
INFO[0031] (service hogehoge) was unable to place a task because no container instance met all of its requirements. The closest matching (container-instance a1b2c3d4-e5f6-g7h8-j9k0-l1m2n3o4p5q6) has insufficient memory available. For more information, see the Troubleshooting section of the Amazon ECS Developer Guide. timestamp=2018-03-09 15:45:24 +0000 UTC
タスク更新(ecs-cli compose service up
)実行時、
上記の様なメモリ不足が出る場合はインスタンスタイプを上げる、また、他タスクを削除する等、メモリーリソースを増やす対応が必要です。
no space on device
no space on device で イメージを pull できない。
df -hT
コマンドで 容量の使用状況確認
未使用のコンテナ・ボリュームを強制削除しお掃除
docker system prune -af --volumes
msg="Couldn't run containers" reason="RESOURCE:CPU"
msg="Couldn't run containers" reason="RESOURCE:CPU"
タスクで指定している cpu (vCPU) が不足しています。 インスタンスタイプを上げる、もしくは、他タスクを削除する等、 CPU リソースを増やす対応が必要です。
Fargate - Port Mapping Error
level=error msg="Create task definition failed" error="ClientException: When networkMode=awsvpc, the host ports and container ports in port mappings must match.\n\tstatus code: 400, request id: a1b2c3d4-e5f6-g7h8-j9k0-l1m2n3o4p5q6"
起動タイプ Fargate で以下の様な設定だと、NG
ports: - "80"
こちらだと OK。
ports: - "80:80"
ホストポートとコンテナポートのマッピングが必要です。
Fargate volume_from は利用できない
volume_from
は Fargate では使用できません。
level=error msg="Create task definition failed" error="ClientException: host.sourcePath should not be set for volumes in Fargate.\n\tstatus code: 400, request id: a1b2c3d4-e5f6-g7h8-j9k0-l1m2n3o4p5q6"
指定された IAM Role が適切なパーミッションを与えられていない
IAM Role に権限を適宜付与します。
level=info msg="(service hogehoge) failed to launch a task with (error ECS was unable to assume the role 'arn:aws:iam::123456789012:role/ecsTask ExecutionRole' that was provided for this task. Please verify that the role being passed has the proper trust relationship and permissions and that your IAM user has permissions to pass this role.)." timestamp=2018-06-21 08:15:43 +0000 UTC
イメージ pull できないというエラーも権限を付与していないことに起因することが主です。
CannotPullContainerError: API error (500): Get https://123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/v2/: net/http: request canceled while waiting for connection"
現在稼働している ECS の IAM Role の権限を参考してください。変更される可能性があるのであくまで参考にし、適宜最新の情報を以ってご対応ください。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Action": [ "logs:PutLogEvents", "logs:CreateLogStream", "logs:CreateLogGroup", "elasticloadbalancing:RegisterTargets", "elasticloadbalancing:Describe*", "elasticloadbalancing:DeregisterTargets", "ecs:UpdateService", "ecs:Submit*", "ecs:StartTelemetrySession", "ecs:StartTask", "ecs:RunTask", "ecs:RegisterTaskDefinition", "ecs:RegisterContainerInstance", "ecs:Poll", "ecs:ListTasks", "ecs:DiscoverPollEndpoint", "ecs:DescribeTasks", "ecs:DescribeServices", "ecs:DescribeContainerInstances", "ecs:DeregisterContainerInstance", "ecs:CreateService", "ecr:UploadLayerPart", "ecr:PutImage", "ecr:InitiateLayerUpload", "ecr:GetDownloadUrlForLayer", "ecr:GetAuthorizationToken", "ecr:CompleteLayerUpload", "ecr:BatchGetImage", "ecr:BatchCheckLayerAvailability", "ec2:Describe*" ], "Resource": "*" } ] }
以上です。
また何か発生したら追記していきたいと思います。