diff --git a/api/client/hijack.go b/api/client/hijack.go index 63fd8edb75..a14376c79e 100644 --- a/api/client/hijack.go +++ b/api/client/hijack.go @@ -25,14 +25,14 @@ func (cli *DockerCli) dial() (net.Conn, error) { return net.Dial(cli.proto, cli.addr) } -func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, body interface{}) error { +func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, data interface{}) error { defer func() { if started != nil { close(started) } }() - params, err := cli.getUrlBody(body) + params, err := cli.encodeData(data) if err != nil { return err } diff --git a/api/client/utils.go b/api/client/utils.go index e1d829e6da..7bbcf06cf6 100644 --- a/api/client/utils.go +++ b/api/client/utils.go @@ -40,7 +40,7 @@ func (cli *DockerCli) HTTPClient() *http.Client { return &http.Client{Transport: tr} } -func (cli *DockerCli) getUrlBody(data interface{}) (*bytes.Buffer, error) { +func (cli *DockerCli) encodeData(data interface{}) (*bytes.Buffer, error) { params := bytes.NewBuffer(nil) if data != nil { if env, ok := data.(engine.Env); ok { @@ -61,7 +61,7 @@ func (cli *DockerCli) getUrlBody(data interface{}) (*bytes.Buffer, error) { } func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo bool) (io.ReadCloser, int, error) { - params, err := cli.getUrlBody(data) + params, err := cli.encodeData(data) if err != nil { return nil, -1, err } diff --git a/daemon/attach.go b/daemon/attach.go index 88883e7a77..c6163494c5 100644 --- a/daemon/attach.go +++ b/daemon/attach.go @@ -128,7 +128,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t // Connect stdin of container to the http conn. if stdin != nil && openStdin { - nJobs += 1 + nJobs++ // Get the stdin pipe. if cStdin, err := streamConfig.StdinPipe(); err != nil { errors <- err @@ -166,7 +166,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t } } if stdout != nil { - nJobs += 1 + nJobs++ // Get a reader end of a pipe that is attached as stdout to the container. if p, err := streamConfig.StdoutPipe(); err != nil { errors <- err @@ -260,7 +260,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t // FIXME: how to clean up the stdin goroutine without the unwanted side effect // of closing the passed stdin? Add an intermediary io.Pipe? - for i := 0; i < nJobs; i += 1 { + for i := 0; i < nJobs; i++ { log.Debugf("attach: waiting for job %d/%d", i+1, nJobs) if err := <-errors; err != nil { log.Errorf("attach: job %d returned error %s, aborting all jobs", i+1, err) diff --git a/daemon/exec.go b/daemon/exec.go index 44bdbfe1d3..da7faa27cc 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -24,7 +24,7 @@ type ExecConfig struct { func (d *Daemon) ContainerExec(job *engine.Job) engine.Status { if len(job.Args) != 1 { - return job.Errorf("Usage: %s container_id command", job.Name) + return job.Errorf("Usage: %s [options] container command [args]", job.Name) } var ( @@ -40,7 +40,7 @@ func (d *Daemon) ContainerExec(job *engine.Job) engine.Status { return job.Errorf("No such container: %s", name) } - if !container.State.IsRunning() { + if !container.IsRunning() { return job.Errorf("Container %s is not not running", name) } diff --git a/daemon/execdriver/native/exec.go b/daemon/execdriver/native/exec.go index 02d627d3ed..0f7e5c07bd 100644 --- a/daemon/execdriver/native/exec.go +++ b/daemon/execdriver/native/exec.go @@ -16,15 +16,16 @@ import ( "github.com/docker/libcontainer/namespaces" ) -const commandName = "nsenter-exec" +const execCommandName = "nsenter-exec" func init() { - reexec.Register(commandName, nsenterExec) + reexec.Register(execCommandName, nsenterExec) } func nsenterExec() { runtime.LockOSThread() + // User args are passed after '--' in the command line. userArgs := findUserArgs() config, err := loadConfigFromFd() diff --git a/daemon/execdriver/native/utils.go b/daemon/execdriver/native/utils.go index ee05b246e3..e337cf4316 100644 --- a/daemon/execdriver/native/utils.go +++ b/daemon/execdriver/native/utils.go @@ -10,16 +10,12 @@ import ( ) func findUserArgs() []string { - i := 0 - for _, a := range os.Args { - i++ - + for i, a := range os.Args { if a == "--" { - break + return os.Args[i+1:] } } - - return os.Args[i:] + return []string{} } // loadConfigFromFd loads a container's config from the sync pipe that is provided by diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index ff3fd3a949..7399585783 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -1297,7 +1297,7 @@ It is even useful to cherry-pick particular tags of an image repository ## exec - Usage: docker exec CONTAINER COMMAND [ARG...] + Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in an existing container diff --git a/runconfig/exec.go b/runconfig/exec.go index abbb985d7c..07de3e43bc 100644 --- a/runconfig/exec.go +++ b/runconfig/exec.go @@ -27,8 +27,8 @@ func ExecConfigFromJob(job *engine.Job) *ExecConfig { AttachStderr: job.GetenvBool("AttachStderr"), AttachStdout: job.GetenvBool("AttachStdout"), } - if Cmd := job.GetenvList("Cmd"); Cmd != nil { - execConfig.Cmd = Cmd + if cmd := job.GetenvList("Cmd"); cmd != nil { + execConfig.Cmd = cmd } return execConfig