Home > Back-end >  Why do I get CannotStartContainerError when trying to start my ECS task?
Why do I get CannotStartContainerError when trying to start my ECS task?

Time:12-15

I have a FastAPI application with the below Dockerfile.

FROM python:3.8

WORKDIR /usr/src/app

COPY . .

RUN pip install --no-cache-dir -r requirements.txt

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "5000"]

Everything runs correctly in Localhost and I can get the project of port 8888. I now want to deploy this project on AWS so I've created a repository on ECR service and pushed my images on this repository. I've then created a cluster & added a task.

The container of the defined task has a hard memory default limit of 128 MiB, uses an image stored in ECR and has correct port mappings.

When I want to run this task on the defined cluster, the status is set to STOPPED after adding and I get the below error:

CannotStartContainerError: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: container init was OOM-killed (memory limit too low?): unknown

How can I solve this problem?

CodePudding user response:

Your task (container) is being stopped because it is trying to use more memory than it is allowed.

The AWS documentation highlights this behaviour:

If your container attempts to exceed the memory specified here, the container is killed.

The main hints here are the mention of OOM (out of memory) & the memory limit too low? question in the error message.

Increase your hard memory limit from 128MiB to around 300-500MiB, which is the ECS recommended memory range for web applications.

Once it just 'works', fine-tune the memory parameter according to your container needs.

  • Related