Failed to handle stdin with `docker exec -i`
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"
this is a regression from 2.x to 3.0
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 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.
@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.