AWS ECS Task Stuck at PROVISIONING – How to Resolve

amazon-ecsamazon-web-servicesdocker

I have an ECS Cluster with a capacity provider and a service. The capacity provider runs an autoscale group, and when one instance of this group starts, at the end I can see that there are ECS instances avalaible. Actually, I can connect to them through SSH.

The service also runs well, since it creates a new task which is based on a docker image at ERS repository. However, the task never pass from "PROVISIONING", and if I open the task I can see that the container of the task is void and loading. If I enter into my instance, I see the same docker instance if I do docker ps or docker ps -a. If I execute the agent docker exec id_docker /agent I see:

level=info time=2022-05-02T21:16:05Z msg="Successfully got ECS instance credentials from provider: EC2RoleProvider" module=instancecreds.go
level=info time=2022-05-02T21:16:05Z msg="Starting Amazon ECS Agent" version="1.61.0" commit="05730614"
level=info time=2022-05-02T21:16:05Z msg="Loading configuration"
level=info time=2022-05-02T21:16:05Z msg="Successfully got ECS instance credentials from provider: EC2RoleProvider" module=instancecreds.go

If I try with docker exec id_docker bash I get an error:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "bash": executable file not found in $PATH: unknown

What's happening here? Any clue?

Best Answer

What I had after doing docker ps wsa in fact ecs-agent, which is something Amazon creates to control the container. That was the stucked part. My docker wasn't even running in fact.

To solve it, when you create the task, in the container options, when you select the ports of the container to redirect to the host, put in your host values a 0. E.g, redirect port 22 to 22 -> 0 to 22. This is a dynamic port mapping in ecs.

Related Topic