diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index ad8c04d04c..4785434c91 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -86,8 +86,9 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error { return err } + detachKeys := dockerCli.ConfigFile().DetachKeys if opts.detachKeys != "" { - dockerCli.ConfigFile().DetachKeys = opts.detachKeys + detachKeys = opts.detachKeys } options := types.ContainerAttachOptions{ @@ -95,7 +96,7 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error { Stdin: !opts.noStdin && c.Config.OpenStdin, Stdout: true, Stderr: true, - DetachKeys: dockerCli.ConfigFile().DetachKeys, + DetachKeys: detachKeys, } var in io.ReadCloser diff --git a/cli/command/container/run.go b/cli/command/container/run.go index cfb7a7fb75..fe4969cd0b 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -169,11 +169,18 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio } attach := config.AttachStdin || config.AttachStdout || config.AttachStderr if attach { + detachKeys := dockerCli.ConfigFile().DetachKeys if opts.detachKeys != "" { - dockerCli.ConfigFile().DetachKeys = opts.detachKeys + detachKeys = opts.detachKeys } - closeFn, err := attachContainer(ctx, dockerCli, &errCh, config, containerID) + closeFn, err := attachContainer(ctx, dockerCli, containerID, &errCh, config, types.ContainerAttachOptions{ + Stream: true, + Stdin: config.AttachStdin, + Stdout: config.AttachStdout, + Stderr: config.AttachStderr, + DetachKeys: detachKeys, + }) if err != nil { return err } @@ -232,15 +239,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio return nil } -func attachContainer(ctx context.Context, dockerCli command.Cli, errCh *chan error, config *container.Config, containerID string) (func(), error) { - options := types.ContainerAttachOptions{ - Stream: true, - Stdin: config.AttachStdin, - Stdout: config.AttachStdout, - Stderr: config.AttachStderr, - DetachKeys: dockerCli.ConfigFile().DetachKeys, - } - +func attachContainer(ctx context.Context, dockerCli command.Cli, containerID string, errCh *chan error, config *container.Config, options types.ContainerAttachOptions) (func(), error) { resp, errAttach := dockerCli.Client().ContainerAttach(ctx, containerID, options) if errAttach != nil { return nil, errAttach @@ -250,13 +249,13 @@ func attachContainer(ctx context.Context, dockerCli command.Cli, errCh *chan err out, cerr io.Writer in io.ReadCloser ) - if config.AttachStdin { + if options.Stdin { in = dockerCli.In() } - if config.AttachStdout { + if options.Stdout { out = dockerCli.Out() } - if config.AttachStderr { + if options.Stderr { if config.Tty { cerr = dockerCli.Out() } else { diff --git a/cli/command/container/start.go b/cli/command/container/start.go index 9a8a083e6b..b50f6ba19a 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -94,8 +94,9 @@ func RunStart(dockerCli command.Cli, opts *StartOptions) error { defer signal.StopCatch(sigc) } + detachKeys := dockerCli.ConfigFile().DetachKeys if opts.DetachKeys != "" { - dockerCli.ConfigFile().DetachKeys = opts.DetachKeys + detachKeys = opts.DetachKeys } options := types.ContainerAttachOptions{ @@ -103,7 +104,7 @@ func RunStart(dockerCli command.Cli, opts *StartOptions) error { Stdin: opts.OpenStdin && c.Config.OpenStdin, Stdout: true, Stderr: true, - DetachKeys: dockerCli.ConfigFile().DetachKeys, + DetachKeys: detachKeys, } var in io.ReadCloser