mirror of https://github.com/docker/docs.git
Fixed a bug preventing proper reattachment to stdin upon container restart
This commit is contained in:
parent
f2c2d953a8
commit
0da9ccc18e
|
@ -355,6 +355,11 @@ func (container *Container) monitor() {
|
||||||
log.Printf("%v: Failed to umount filesystem: %v", container.Id, err)
|
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
|
// Report status back
|
||||||
container.State.setStopped(exitCode)
|
container.State.setStopped(exitCode)
|
||||||
container.save()
|
container.save()
|
||||||
|
|
|
@ -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) {
|
func TestUser(t *testing.T) {
|
||||||
docker, err := newTestDocker()
|
docker, err := newTestDocker()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue