2022-12-02

Solution for "exec format error" During ECS Task Launch

"exec format error" Occurs When Launching ECS Tasks

I encountered a problem where the container would not start when launching ECS tasks after creating a Docker image for FastAPI in my local environment and pushing it to ECR.

The following error was displayed when I checked the logs.

exec /usr/local/bin/uvicorn: exec format error

ECS console

In this article, I will introduce how to resolve the exec format error.

Cause: M1/M2 Chip

This error seems to occur when the CPU architecture of the machine that builds Docker is different from the machine that runs it. My PC is a Mac with an M2 chip, so it seems to have occurred because it was different from the CPU architecture of the machine for ECS Fargate, which is the execution environment.

Solution

The problem can be solved by adding the --platform amd64 parameter during the Docker build.

bash
$ docker build --platform amd64 .

References

https://axcoto.com/notes/2021-03-13-docker-apple-m-nginx-and-standard-init-linux-go-exec-user-process-caused-exec-format-error-/

Ryusei Kakujo

researchgatelinkedingithub

Focusing on data science for mobility

Bench Press 100kg!