From 7bdb4df07da0d6f5046f6073213d30c4973420c4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 31 Oct 2025 14:59:08 +0100 Subject: [PATCH] cli/command/container: use ImagePull instead of ImageCreate Signed-off-by: Sebastiaan van Stijn --- cli/command/container/client_test.go | 18 +++++++++++++----- cli/command/container/create.go | 6 +++--- cli/command/container/create_test.go | 4 ++-- cli/command/container/run_test.go | 4 ++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cli/command/container/client_test.go b/cli/command/container/client_test.go index 3dc0be972080..6f99b171dcb6 100644 --- a/cli/command/container/client_test.go +++ b/cli/command/container/client_test.go @@ -32,6 +32,14 @@ func mockContainerLogsResult(content string) client.ContainerLogsResult { return out } +type fakeStreamResult struct { + io.ReadCloser + client.ImagePushResponse // same interface as [client.ImagePushResponse] +} + +func (e fakeStreamResult) Read(p []byte) (int, error) { return e.ReadCloser.Read(p) } +func (e fakeStreamResult) Close() error { return e.ReadCloser.Close() } + type fakeClient struct { client.Client inspectFunc func(string) (client.ContainerInspectResult, error) @@ -39,7 +47,7 @@ type fakeClient struct { execCreateFunc func(containerID string, options client.ExecCreateOptions) (client.ExecCreateResult, error) createContainerFunc func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error) containerStartFunc func(containerID string, options client.ContainerStartOptions) (client.ContainerStartResult, error) - imageCreateFunc func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) + imagePullFunc func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) infoFunc func() (client.SystemInfoResult, error) containerStatPathFunc func(containerID, path string) (client.ContainerStatPathResult, error) containerCopyFromFunc func(containerID, srcPath string) (client.CopyFromContainerResult, error) @@ -107,11 +115,11 @@ func (f *fakeClient) ContainerRemove(ctx context.Context, containerID string, op return client.ContainerRemoveResult{}, nil } -func (f *fakeClient) ImageCreate(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) { - if f.imageCreateFunc != nil { - return f.imageCreateFunc(ctx, parentReference, options) +func (f *fakeClient) ImagePull(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) { + if f.imagePullFunc != nil { + return f.imagePullFunc(ctx, parentReference, options) } - return client.ImageCreateResult{}, nil + return fakeStreamResult{}, nil } func (f *fakeClient) Info(context.Context, client.InfoOptions) (client.SystemInfoResult, error) { diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 815cdd450be5..1820040784e3 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -140,7 +140,7 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options * // Already validated. ociPlatforms = append(ociPlatforms, platforms.MustParse(options.platform)) } - resp, err := dockerCli.Client().ImageCreate(ctx, img, client.ImageCreateOptions{ + resp, err := dockerCli.Client().ImagePull(ctx, img, client.ImagePullOptions{ RegistryAuth: encodedAuth, Platforms: ociPlatforms, }) @@ -148,14 +148,14 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options * return err } defer func() { - _ = resp.Body.Close() + _ = resp.Close() }() out := dockerCli.Err() if options.quiet { out = streams.NewOut(io.Discard) } - return jsonstream.Display(ctx, resp.Body, out) + return jsonstream.Display(ctx, resp, out) } type cidFile struct { diff --git a/cli/command/container/create_test.go b/cli/command/container/create_test.go index 5a0d7d66547a..4491a725f28d 100644 --- a/cli/command/container/create_test.go +++ b/cli/command/container/create_test.go @@ -124,9 +124,9 @@ func TestCreateContainerImagePullPolicy(t *testing.T) { return client.ContainerCreateResult{ID: containerID}, nil } }, - imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) { + imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) { defer func() { pullCounter++ }() - return client.ImageCreateResult{Body: io.NopCloser(strings.NewReader(""))}, nil + return fakeStreamResult{ReadCloser: io.NopCloser(strings.NewReader(""))}, nil }, infoFunc: func() (client.SystemInfoResult, error) { return client.SystemInfoResult{ diff --git a/cli/command/container/run_test.go b/cli/command/container/run_test.go index 5a8f27c0e4ea..4772bee0b315 100644 --- a/cli/command/container/run_test.go +++ b/cli/command/container/run_test.go @@ -235,7 +235,7 @@ func TestRunPullTermination(t *testing.T) { containerAttachFunc: func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error) { return client.ContainerAttachResult{}, errors.New("shouldn't try to attach to a container") }, - imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) { + imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) { server, respReader := net.Pipe() t.Cleanup(func() { _ = server.Close() @@ -260,7 +260,7 @@ func TestRunPullTermination(t *testing.T) { } }() attachCh <- struct{}{} - return client.ImageCreateResult{Body: respReader}, nil + return fakeStreamResult{ReadCloser: respReader}, nil }, Version: client.MaxAPIVersion, })