fix(cp): return non-nil Content from dry-run CopyFromContainer

The caller in pkg/compose/cp.go unconditionally defers
res.Content.Close() once the call succeeds. The dry-run client
returned a zero-value result with a nil Content reader, so
`docker compose cp --dry-run <ctr>:<path> <dst>` panicked with a
nil pointer dereference. Return an empty NopCloser instead, matching
the pattern already used for the other stream results in this file.

Signed-off-by: Guillaume Lours <[email protected]>
This commit is contained in:
Guillaume Lours
2026-07-30 11:37:49 +02:00
committed by Guillaume Lours
parent aa518b9c3a
commit 367f1d5701
+3 -1
View File
@@ -191,7 +191,9 @@ func (d *DryRunClient) CopyFromContainer(ctx context.Context, container string,
if _, err := d.ContainerStatPath(ctx, container, client.ContainerStatPathOptions{Path: options.SourcePath}); err != nil {
return client.CopyFromContainerResult{}, fmt.Errorf("could not find the file %s in container %s", options.SourcePath, container)
}
return client.CopyFromContainerResult{}, nil
return client.CopyFromContainerResult{
Content: io.NopCloser(bytes.NewReader(nil)),
}, nil
}
func (d *DryRunClient) CopyToContainer(ctx context.Context, container string, options client.CopyToContainerOptions) (client.CopyToContainerResult, error) {