| ... | ... |
@@ -355,6 +355,11 @@ func (container *Container) monitor() {
|
| 355 | 355 |
log.Printf("%v: Failed to umount filesystem: %v", container.Id, err)
|
| 356 | 356 |
} |
| 357 | 357 |
|
| 358 |
+ // Re-create a brand new stdin pipe once the container exited |
|
| 359 |
+ if container.Config.OpenStdin {
|
|
| 360 |
+ container.stdin, container.stdinPipe = io.Pipe() |
|
| 361 |
+ } |
|
| 362 |
+ |
|
| 358 | 363 |
// Report status back |
| 359 | 364 |
container.State.setStopped(exitCode) |
| 360 | 365 |
container.save() |
| ... | ... |
@@ -221,6 +221,55 @@ func TestRestart(t *testing.T) {
|
| 221 | 221 |
} |
| 222 | 222 |
} |
| 223 | 223 |
|
| 224 |
+func TestRestartStdin(t *testing.T) {
|
|
| 225 |
+ docker, err := newTestDocker() |
|
| 226 |
+ if err != nil {
|
|
| 227 |
+ t.Fatal(err) |
|
| 228 |
+ } |
|
| 229 |
+ container, err := docker.Create( |
|
| 230 |
+ "restart_stdin_test", |
|
| 231 |
+ "cat", |
|
| 232 |
+ []string{},
|
|
| 233 |
+ []string{"/var/lib/docker/images/ubuntu"},
|
|
| 234 |
+ &Config{
|
|
| 235 |
+ OpenStdin: true, |
|
| 236 |
+ }, |
|
| 237 |
+ ) |
|
| 238 |
+ if err != nil {
|
|
| 239 |
+ t.Fatal(err) |
|
| 240 |
+ } |
|
| 241 |
+ defer docker.Destroy(container) |
|
| 242 |
+ |
|
| 243 |
+ stdin, err := container.StdinPipe() |
|
| 244 |
+ stdout, err := container.StdoutPipe() |
|
| 245 |
+ if err := container.Start(); err != nil {
|
|
| 246 |
+ t.Fatal(err) |
|
| 247 |
+ } |
|
| 248 |
+ io.WriteString(stdin, "hello world") |
|
| 249 |
+ stdin.Close() |
|
| 250 |
+ container.Wait() |
|
| 251 |
+ output, err := ioutil.ReadAll(stdout) |
|
| 252 |
+ stdout.Close() |
|
| 253 |
+ if string(output) != "hello world" {
|
|
| 254 |
+ t.Fatal(string(output)) |
|
| 255 |
+ } |
|
| 256 |
+ |
|
| 257 |
+ // Restart and try again |
|
| 258 |
+ stdin, err = container.StdinPipe() |
|
| 259 |
+ stdout, err = container.StdoutPipe() |
|
| 260 |
+ if err := container.Start(); err != nil {
|
|
| 261 |
+ t.Fatal(err) |
|
| 262 |
+ } |
|
| 263 |
+ io.WriteString(stdin, "hello world #2") |
|
| 264 |
+ stdin.Close() |
|
| 265 |
+ container.Wait() |
|
| 266 |
+ output, err = ioutil.ReadAll(stdout) |
|
| 267 |
+ stdout.Close() |
|
| 268 |
+ if string(output) != "hello world #2" {
|
|
| 269 |
+ t.Fatal(string(output)) |
|
| 270 |
+ } |
|
| 271 |
+} |
|
| 272 |
+ |
|
| 224 | 273 |
func TestUser(t *testing.T) {
|
| 225 | 274 |
docker, err := newTestDocker() |
| 226 | 275 |
if err != nil {
|