4

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

clay
  • 18,138
  • 28
  • 107
  • 192
  • I am confused. If you only need/want to run a command and then exit why would you want to launch the task and then `ecs exec` into it? The proper pattern would be to launch the command overriding the `entrypoint`/`command` with the command you want to use no? – mreferre Sep 20 '21 at 16:52
  • So, I want to run an interactive shell command, not just any command. Interactive shell support is a new feature, most ECS isn't designed for that. I can specify or override entrypoint / command in the ECS TaskDefinition. I need to use `execute-command` to get an interactive shell (AFAIK). – clay Sep 20 '21 at 16:58
  • 1
    So if you need to interact with the shell then yes you need to use `ecs exec`. The suggestion Mark is providing seems to be a good way to achieve it. – mreferre Sep 20 '21 at 17:35
  • 1
    Your main question is already answered below, but the error message you got when trying to run `sleep 10000` is because you're unintentionally asking to run a binary literally called "sleep 10000". Arguments are accepted as an array, so the easiest way to do this would be to specify `"sleep", "10000"` instead of `"sleep 10000"`. If you also end up wanting to run a little shell script, you can use something like `"sh", "-c", "sleep 10000"` instead. – Samuel Karp Sep 20 '21 at 19:42

1 Answers1

2

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.

Mark B
  • 183,023
  • 24
  • 297
  • 295