diff --git a/container.go b/container.go index 7e1fe79d34..57ec531737 100644 --- a/container.go +++ b/container.go @@ -355,6 +355,11 @@ func (container *Container) monitor() { log.Printf("%v: Failed to umount filesystem: %v", container.Id, err) } + // Re-create a brand new stdin pipe once the container exited + if container.Config.OpenStdin { + container.stdin, container.stdinPipe = io.Pipe() + } + // Report status back container.State.setStopped(exitCode) container.save() diff --git a/container_test.go b/container_test.go index 2aa71742ad..ada49f81e3 100644 --- a/container_test.go +++ b/container_test.go @@ -221,6 +221,55 @@ func TestRestart(t *testing.T) { } } +func TestRestartStdin(t *testing.T) { + docker, err := newTestDocker() + if err != nil { + t.Fatal(err) + } + container, err := docker.Create( + "restart_stdin_test", + "cat", + []string{}, + []string{"/var/lib/docker/images/ubuntu"}, + &Config{ + OpenStdin: true, + }, + ) + if err != nil { + t.Fatal(err) + } + defer docker.Destroy(container) + + stdin, err := container.StdinPipe() + stdout, err := container.StdoutPipe() + if err := container.Start(); err != nil { + t.Fatal(err) + } + io.WriteString(stdin, "hello world") + stdin.Close() + container.Wait() + output, err := ioutil.ReadAll(stdout) + stdout.Close() + if string(output) != "hello world" { + t.Fatal(string(output)) + } + + // Restart and try again + stdin, err = container.StdinPipe() + stdout, err = container.StdoutPipe() + if err := container.Start(); err != nil { + t.Fatal(err) + } + io.WriteString(stdin, "hello world #2") + stdin.Close() + container.Wait() + output, err = ioutil.ReadAll(stdout) + stdout.Close() + if string(output) != "hello world #2" { + t.Fatal(string(output)) + } +} + func TestUser(t *testing.T) { docker, err := newTestDocker() if err != nil {