I'm trying to detach and reattach to a Docker container started with docker run
in foreground mode. The issue I'm seeing is that during the initial detach Docker closes STDIN unexpectedly.
Here's an example script:
/tmp/echo.sh
#!/bin/bash
while read line
do
echo "Received: $line"
done < "${1:-/dev/stdin}"
echo "STDIN closed"
while [ 1 ]; do
echo "Still alive"
done
So in theory I do this:
# docker run -i --sig-proxy=false --name=test --volume=/tmp:/tmp debian /tmp/echo.sh
Then CTRL+C which ends the docker run
command (the INT signal is not forwarded), then:
# docker attach --sig-proxy=false test
The issue I'm seeing is that closing the docker run
command also closes STDIN. The container continues running and when using docker attach
it just spams Still alive
.
However, if I run the following, then STDIN is kept open:
docker run -di --sig-proxy=false --name=test --volume=/tmp:/tmp debian /tmp/echo.sh
I can then use docker attach
as expected, close the docker attach
process with CTRL+C and run it again with STDIN staying open the entire time.
How can I close the initial docker run
command without closing STDIN and without starting in detached mode?