diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 7f66b96e59..18c432f76a 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -12,6 +12,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/image" + "github.com/docker/cli/cli/streams" "github.com/docker/cli/opts" "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" @@ -111,7 +112,8 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, options *createOptio return nil } -func pullImage(ctx context.Context, dockerCli command.Cli, image string, platform string, out io.Writer) error { +// FIXME(thaJeztah): this is the only code-path that uses APIClient.ImageCreate. Rewrite this to use the regular "pull" code (or vice-versa). +func pullImage(ctx context.Context, dockerCli command.Cli, image string, opts *createOptions) error { encodedAuth, err := command.RetrieveAuthTokenFromImage(ctx, dockerCli, image) if err != nil { return err @@ -119,19 +121,18 @@ func pullImage(ctx context.Context, dockerCli command.Cli, image string, platfor responseBody, err := dockerCli.Client().ImageCreate(ctx, image, types.ImageCreateOptions{ RegistryAuth: encodedAuth, - Platform: platform, + Platform: opts.platform, }) if err != nil { return err } defer responseBody.Close() - return jsonmessage.DisplayJSONMessagesStream( - responseBody, - out, - dockerCli.Out().FD(), - dockerCli.Out().IsTerminal(), - nil) + out := dockerCli.Err() + if opts.quiet { + out = io.Discard + } + return jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(out), nil) } type cidFile struct { @@ -221,11 +222,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c } pullAndTagImage := func() error { - pullOut := dockerCli.Err() - if opts.quiet { - pullOut = io.Discard - } - if err := pullImage(ctx, dockerCli, config.Image, opts.platform, pullOut); err != nil { + if err := pullImage(ctx, dockerCli, config.Image, opts); err != nil { return err } if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {