aws / containers-roadmap

This is the public roadmap for AWS container services (ECS, ECR, Fargate, and EKS).
https://aws.amazon.com/about-aws/whats-new/containers/
Other
5.21k stars 318 forks source link

[ECS] [request]: Allow redirecting STDIN of a container #1223

Open kjkuan opened 3 years ago

kjkuan commented 3 years ago

With docker it's possible to pipe data into a container like this:

$ (echo hello; echo world) | docker run -i ubuntu nl
     1  hello
     2  world
$

However, in ECS, even though it's possible to configure a container to be interactive in its task definition, doing so does not allow one to later pipe data to it. For example, this is possible with docker:

$ docker run --name nl -i ubuntu nl >/dev/null 2>&1 &
[2] 22254
$ (echo hello; echo world) | docker attach nl
     1  hello
     2  world
[2]+  Done                    docker run --name nl -i ubuntu nl > /dev/null 2>&1
$

But, if you have a container that's configured to be interactive (specifically, interactive is true and pseudoTerminal is false) via a task, you can not, later, on the host running the container, docker attach to its STDIN. Doing so blocks the docker attach command and would not return.

I suspect this is because the AttachStdin option in the create container API is not set to true when a container is created. In fact, docker inspect-ing the nl container in the above example, I see:

$ docker inspect nl | grep Attach
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,

However, for a container started by ECS, I see:

            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,

Is there a plan to make these options (maybe the StdinOnce options as well) configurable in a ECS task definition? It would be very convenient for our tooling to be able to pipe data to an one-off container in ECS this way, to avoid having to re-build the docker image to include the data, or having to get the data over the network, in which case we probably have to upload them somewhere first.

Thank you

Community Note

kjkuan commented 3 years ago

As a work around, currently we use docker exec -i ... to feed the input data to a named pipe in the container. The container process will then redirect its STDIN from the named pipe.