A solution might be to use something like:
echo "your input here" | docker attach <your container>
but... this requires to not use the -t
option which might cause you other problems...
Check this issue: Redirect stdin to docker attach
where Michael Crosby provides an example:
This issue has been resolved.
docker run -i busybox sh -c "while true; do cat /dev/stdin; sleep 1; done;"
test
# ... from another terminal
echo test | docker attach 27f04f3fd73a
What should be noticed here is that it doesn't work when you run the container with --tty , -t (Allocate a pseudo-TTY)
option. I haven't understood completely why this happens so I won't try to explain it, some things have been already written here: Confused about Docker -t option to Allocate a pseudo-TTY
Also, from the docker run
reference:
For interactive processes (like a shell), you must use -i
-t
together in order to allocate a tty for the container process. -i
-t
is often written -it
as you’ll see in later examples.Specifying -t
is forbidden when the client is receiving its standard input from a pipe, as in:
$ echo test | docker run -i busybox cat