runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Failed to handle stdin with `docker exec -i`

Open jcvenegas opened this issue 8 years ago • 4 comments

The following case is failing trying to send some date by through a pipe.

echo data | docker exec -i "${container}" bash -c "cat > /f"

Here a script to run and confirm. Note that it works for runc as runtime.

#!/bin/bash
content="test"

test_stdin() {
runtime=$1
#Run a container to run for 30 seconds
docker run --rm --runtime "${runtime}" -d ubuntu bash -c "sleep 30"
last_container=$(docker ps -l -q)
#Send by stdin to text to container | the container will save it in a file
echo $content | docker exec -i "${last_container}" bash -c "cat > /f"
#Check the file has the cogent previously saved 
docker exec -i "${last_container}" bash -c "cat /f" | grep "${content}" || echo "failed"
}

echo "Check with runc"
test_stdin "runc"
echo "Check with cc-runtime"
test_stdin "cc-runtime"

jcvenegas avatar Sep 22 '17 14:09 jcvenegas

this is a regression from 2.x to 3.0

jcvenegas avatar Sep 22 '17 14:09 jcvenegas

From @amshinde "I tried reproducing the issue and was able to do so. The command just hangs. But I do see that the file is successfully created inside the container with the right content, the container process does not seem to send the exit code to the shim process. I can verify this from the shim logs as well, the contents of the file are sent, but it never receives an exit code."

jcvenegas avatar Sep 22 '17 14:09 jcvenegas

@jcvenegas good news, https://github.com/clearcontainers/proxy/pull/170 and https://github.com/clearcontainers/agent/pull/162 fix this issue. The root cause was both the proxy not redirecting empty messages, and the agent not handling the closure of stdin in such cases.

sboeuf avatar Nov 13 '17 22:11 sboeuf

@jcvenegas I think this issue could be closed since clearcontainers/proxy#170 and clearcontainers/agent#162 have been merged. We might want to wait for the agent patch to reallly land into our clear-containers.img though.

sboeuf avatar Nov 16 '17 16:11 sboeuf