0

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?

Zpin
  • 1
  • Is your problem not just about how to put this process in background instead of foreground. Try pressing ctrl+Z instead of ctrl+C – Lorem ipsum Oct 03 '20 at 08:18
  • No, I'd like to completely close any processes I use to run/attach the container, then pick up from where I left off. – Zpin Oct 04 '20 at 09:02

0 Answers0