movee(モビー) オノデラのブログ

(株)movee代表。週末は自社サービスを作っています。

ECSコンテナのエラー原因確認方法

nginxとphp-fpmのコンテナがSTOPPEDになるので原因を探りたい。ただし、コンパネでは必要な情報が足りないので、もうちょっと調査してみる。

その場合の調査方法。 STOPPEDのコンテナを探すためにステータスがSTOPPEDのコンテナをリスト化する。

aws ecs list-tasks --cluster php-sample-cluster --profile onody00  --region ap-northeast-1 --desired-status STOPPED

cluster名、プロファイル名、リージョン名をオプションで付ける。


{
    "taskArns": [
        "arn:aws:ecs:ap-northeast-1:【アカウントID】:task/php-sample-cluster/058bfc5ed3ea4ca38e7d2f1b520fb7c4",
        "arn:aws:ecs:ap-northeast-1:【アカウントID】:task/php-sample-cluster/0c2b82f0113b4c23956ce231bd30723f",
        "arn:aws:ecs:ap-northeast-1:【アカウントID】:task/php-sample-cluster/13f51fb8858a4f2b99f44d419bf90f69",
        "arn:aws:ecs:ap-northeast-1:【アカウントID】:task/php-sample-cluster/19f4afe40a8a448d9dda6c3bb8902e5e",
        "arn:aws:ecs:ap-northeast-1:【アカウントID】:task/php-sample-cluster/1beddc774d1347a493049bad40b755c2",
:...skipping...
{

リストが出てくる。

aws ecs describe-tasks --cluster php-sample-cluster --profile onody00 --region ap-northeast-1 --task arn:aws:ecs:ap-northeast-1:【アカウントID】:task/php-sample-cluster/058bfc5ed3ea4ca38e7d2f1b520fb7c4> error.json

こんな感じでtaskオプションで確認したいタスクを指定してjsonファイルに吐き出す(けっこう長いのでファイルに吐いたほうが調べやすい)

                {
                    "containerArn": "arn:aws:ecs:ap-northeast-1:【アカウントID】:container/php-sample-cluster/058bfc5ed3ea4ca38e7d2f1b520fb7c4/42a4be88-3404-4046-90b1-5de3902d1149",
                    "taskArn": "arn:aws:ecs:ap-northeast-1:【アカウントID】:task/php-sample-cluster/058bfc5ed3ea4ca38e7d2f1b520fb7c4",
                    "name": "nginx",
                    "image": "【アカウントID】.dkr.ecr.ap-northeast-1.amazonaws.com/nginx:latest",
                    "imageDigest": "sha256:ff2a48b91777c2f8093f569f357f7907b88b1f3718c9b9dab256704b9496e57d",
                    "runtimeId": "058bfc5ed3ea4ca38e7d2f1b520fb7c4-2531612879",
                    "lastStatus": "STOPPED",
                    "exitCode": 1,
                    "networkBindings": [],
                    "networkInterfaces": [
                        {
                            "attachmentId": "14d400a1-218d-4056-a56a-33975751eb2c",
                            "privateIpv4Address": "10.0.0.61"
                        }
                    ],
                    "healthStatus": "UNKNOWN",
                    "cpu": "0"
                }
            ],
            "cpu": "256",
            "createdAt": "2023-01-10T16:28:14.120000+09:00",
            "desiredStatus": "STOPPED",
            "enableExecuteCommand": false,
            "executionStoppedAt": "2023-01-10T16:28:31.495000+09:00",

tasks > containers > lastStatusとreasonに色々書いてるらしいが、reason項目はなかったな。。