From 78fee01e678cb658a2f003c24c1bce5f792f5b7f Mon Sep 17 00:00:00 2001 From: Vishnu Kannan Date: Wed, 10 Sep 2014 07:20:05 +0000 Subject: [PATCH] Fix bug in attach handling for docker exec. Add docs for 'docker exec' feature. Docker-DCO-1.1-Signed-off-by: Vishnu Kannan (github: vishh) Upstream-commit: d130c10ab78417ebf64284c2a399304767446c88 Component: engine --- components/engine/daemon/exec.go | 14 +++++------ components/engine/docs/man/docker-exec.md | 29 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 components/engine/docs/man/docker-exec.md diff --git a/components/engine/daemon/exec.go b/components/engine/daemon/exec.go index c27171b4a1..44bdbfe1d3 100644 --- a/components/engine/daemon/exec.go +++ b/components/engine/daemon/exec.go @@ -87,22 +87,22 @@ func (d *Daemon) ContainerExec(job *engine.Job) engine.Status { execConfig.StreamConfig.stdinPipe = ioutils.NopWriteCloser(ioutil.Discard) // Silently drop stdin } - var execErr, attachErr chan error - go func() { - attachErr = d.Attach(&execConfig.StreamConfig, config.AttachStdin, false, config.Tty, cStdin, cStdinCloser, cStdout, cStderr) - }() + attachErr := d.Attach(&execConfig.StreamConfig, config.AttachStdin, false, config.Tty, cStdin, cStdinCloser, cStdout, cStderr) + execErr := make(chan error) go func() { err := container.Exec(execConfig) if err != nil { - err = fmt.Errorf("Cannot run in container %s: %s", name, err) + execErr <- fmt.Errorf("Cannot run in container %s: %s", name, err) } - execErr <- err }() select { case err := <-attachErr: - return job.Errorf("attach failed with error: %s", err) + if err != nil { + return job.Errorf("attach failed with error: %s", err) + } + break case err := <-execErr: return job.Error(err) } diff --git a/components/engine/docs/man/docker-exec.md b/components/engine/docs/man/docker-exec.md new file mode 100644 index 0000000000..2a6979545b --- /dev/null +++ b/components/engine/docs/man/docker-exec.md @@ -0,0 +1,29 @@ +% DOCKER(1) Docker User Manuals +% Docker Community +% SEPT 2014 +# NAME +docker-exec - Run a command in an existing container + +# SYNOPSIS +**docker exec** +[**-d**|**--detach**[=*false*]] +[**-i**|**--interactive**[=*false*]] +[**-t**|**--tty**[=*false*]] + CONTAINER COMMAND [ARG...] + +# DESCRIPTION + +Run a process in an existing container. The existing CONTAINER needs is active. + +# Options + +**-d**, **--detach**=*true*|*false* + Detached mode. This runs the new process in the background. + +**-i**, **--interactive**=*true*|*false* + When set to true, keep stdin open even if not attached. The default is false. + +**-t**, **--tty**=*true*|*false* + When set to true Docker can allocate a pseudo-tty and attach to the standard +input of the process. This can be used, for example, to run a throwaway +interactive shell. The default is value is false.