diff --git a/cli/command/image/load.go b/cli/command/image/load.go index 6ff07b0250..2aeb13c09d 100644 --- a/cli/command/image/load.go +++ b/cli/command/image/load.go @@ -51,7 +51,16 @@ func NewLoadCommand(dockerCli command.Cli) *cobra.Command { func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error { var input io.Reader = dockerCli.In() - if opts.input != "" { + + // TODO(thaJeztah): add support for "-" as STDIN to match other commands, possibly making it a required positional argument. + switch opts.input { + case "": + // To avoid getting stuck, verify that a tar file is given either in + // the input flag or through stdin and if not display an error message and exit. + if dockerCli.In().IsTerminal() { + return errors.Errorf("requested load from stdin, but stdin is empty") + } + default: // We use sequential.Open to use sequential file access on Windows, avoiding // depleting the standby list un-necessarily. On Linux, this equates to a regular os.Open. file, err := sequential.Open(opts.input) @@ -62,12 +71,6 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error input = file } - // To avoid getting stuck, verify that a tar file is given either in - // the input flag or through stdin and if not display an error message and exit. - if opts.input == "" && dockerCli.In().IsTerminal() { - return errors.Errorf("requested load from stdin, but stdin is empty") - } - var options []client.ImageLoadOption if opts.quiet || !dockerCli.Out().IsTerminal() { options = append(options, client.ImageLoadWithQuiet(true))