Home > OS >  Interactive shell in Docker image with Amazon ECS with `aws ecs run-task` followed by `aws ecs execu
Interactive shell in Docker image with Amazon ECS with `aws ecs run-task` followed by `aws ecs execu

Time:09-21

I would like to launch an interactive shell into a public Docker image on my AWS ECS/Fargate cluster to run network/connectivity tests from inside the cluster.

It seems the official way to do this is with aws ecs run-task followed by aws ecs execute-command [1][2]

I'd like to use existing, public Docker Hub images rather than build custom images if possible.

If I run do run-task with no command or the default command, the task exits and execute-command won't work on an exited task.

"Essential container in task exited"

If I set a Docker command of sleep 10000, I get:

"CannotStartContainerError: ResourceInitializationError: failed to create new container runtime task: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: \"sleep 10000\": executable file not found in $PATH: unknown",

Ideally, run-task and execute-command would be combined in one step. I don't want a background task running indefinitely, I want a shell to run a few commands interactively, that is cleaned up when I'm finished. How would I achieve this?

[1] https://aws.amazon.com/blogs/containers/new-using-amazon-ecs-exec-access-your-containers-fargate-ec2/

[2] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html

CodePudding user response:

I had the same issue. I was finally able to get a container to sit "idle" with the following command inside the Task Definition:

"tail", "-F", "/dev/null"

Then I could connect in with an interactive execute-command.

  • Related