From aba8821f605ef14c8da7ff6e7f5ab5cbbca0f0dd Mon Sep 17 00:00:00 2001 From: Lifubang Date: Mon, 22 Oct 2018 18:53:22 +0800 Subject: [PATCH] don't need to type ssh password twice when docker logs with ssh Signed-off-by: Lifubang --- cli/command/container/logs.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/command/container/logs.go b/cli/command/container/logs.go index b5b526f2e2..d9bc73baff 100644 --- a/cli/command/container/logs.go +++ b/cli/command/container/logs.go @@ -50,6 +50,11 @@ func NewLogsCommand(dockerCli command.Cli) *cobra.Command { func runLogs(dockerCli command.Cli, opts *logsOptions) error { ctx := context.Background() + c, err := dockerCli.Client().ContainerInspect(ctx, opts.container) + if err != nil { + return err + } + options := types.ContainerLogsOptions{ ShowStdout: true, ShowStderr: true, @@ -60,17 +65,12 @@ func runLogs(dockerCli command.Cli, opts *logsOptions) error { Tail: opts.tail, Details: opts.details, } - responseBody, err := dockerCli.Client().ContainerLogs(ctx, opts.container, options) + responseBody, err := dockerCli.Client().ContainerLogs(ctx, c.ID, options) if err != nil { return err } defer responseBody.Close() - c, err := dockerCli.Client().ContainerInspect(ctx, opts.container) - if err != nil { - return err - } - if c.Config.Tty { _, err = io.Copy(dockerCli.Out(), responseBody) } else {