Close stdin after execution with `docker exec -i`
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
parent
f10fefe408
commit
165624062e
|
@ -203,7 +203,7 @@ func (d *Daemon) ContainerExecStart(job *engine.Job) engine.Status {
|
||||||
execConfig.StreamConfig.stdinPipe = ioutils.NopWriteCloser(ioutil.Discard) // Silently drop stdin
|
execConfig.StreamConfig.stdinPipe = ioutils.NopWriteCloser(ioutil.Discard) // Silently drop stdin
|
||||||
}
|
}
|
||||||
|
|
||||||
attachErr := d.attach(&execConfig.StreamConfig, execConfig.OpenStdin, false, execConfig.ProcessConfig.Tty, cStdin, cStdout, cStderr)
|
attachErr := d.attach(&execConfig.StreamConfig, execConfig.OpenStdin, true, execConfig.ProcessConfig.Tty, cStdin, cStdout, cStderr)
|
||||||
|
|
||||||
execErr := make(chan error)
|
execErr := make(chan error)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -31,6 +32,47 @@ func TestExec(t *testing.T) {
|
||||||
logDone("exec - basic test")
|
logDone("exec - basic test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExecInteractiveStdinClose(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "busybox", "/bin/cat"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
contId := strings.TrimSpace(out)
|
||||||
|
println(contId)
|
||||||
|
|
||||||
|
returnchan := make(chan struct{})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
var err error
|
||||||
|
cmd := exec.Command(dockerBinary, "exec", "-i", contId, "/bin/ls", "/")
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(out) == "" {
|
||||||
|
t.Fatalf("Output was empty, likely blocked by standard input")
|
||||||
|
}
|
||||||
|
|
||||||
|
returnchan <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-returnchan:
|
||||||
|
case <-time.After(10 * time.Second):
|
||||||
|
t.Fatal("timed out running docker exec")
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("exec - interactive mode closes stdin after execution")
|
||||||
|
}
|
||||||
|
|
||||||
func TestExecInteractive(t *testing.T) {
|
func TestExecInteractive(t *testing.T) {
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && sleep 100")
|
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && sleep 100")
|
||||||
if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
|
if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue