@@ -24,6 +24,8 @@ import (
24
24
"path/filepath"
25
25
"strings"
26
26
27
+ "golang.org/x/sync/errgroup"
28
+
27
29
"github.com/compose-spec/compose-go/types"
28
30
"github.com/docker/cli/cli/command"
29
31
"github.com/docker/compose-cli/api/compose"
@@ -51,19 +53,25 @@ func (s *composeService) Copy(ctx context.Context, project *types.Project, opts
51
53
if srcService != "" {
52
54
direction |= fromService
53
55
serviceName = srcService
56
+
57
+ // copying from multiple containers of a services doesn't make sense.
58
+ if opts .All {
59
+ return errors .New ("cannot use the --all flag when copying from a service" )
60
+ }
54
61
}
55
62
if destService != "" {
56
63
direction |= toService
57
64
serviceName = destService
58
65
}
59
66
60
- containers , err := s .apiClient .ContainerList (ctx , apitypes.ContainerListOptions {
61
- Filters : filters .NewArgs (
62
- projectFilter (project .Name ),
63
- serviceFilter (serviceName ),
64
- filters .Arg ("label" , fmt .Sprintf ("%s=%d" , containerNumberLabel , opts .Index )),
65
- ),
66
- })
67
+ f := filters .NewArgs (
68
+ projectFilter (project .Name ),
69
+ serviceFilter (serviceName ),
70
+ )
71
+ if ! opts .All {
72
+ f .Add ("label" , fmt .Sprintf ("%s=%d" , containerNumberLabel , opts .Index ))
73
+ }
74
+ containers , err := s .apiClient .ContainerList (ctx , apitypes.ContainerListOptions {Filters : f })
67
75
if err != nil {
68
76
return err
69
77
}
@@ -72,17 +80,25 @@ func (s *composeService) Copy(ctx context.Context, project *types.Project, opts
72
80
return fmt .Errorf ("service %s not running" , serviceName )
73
81
}
74
82
75
- containerID := containers [0 ].ID
76
- switch direction {
77
- case fromService :
78
- return s .copyFromContainer (ctx , containerID , srcPath , dstPath , opts )
79
- case toService :
80
- return s .copyToContainer (ctx , containerID , srcPath , dstPath , opts )
81
- case acrossServices :
82
- return errors .New ("copying between services is not supported" )
83
- default :
84
- return errors .New ("unknown copy direction" )
83
+ g := errgroup.Group {}
84
+ for i := range containers {
85
+ containerID := containers [i ].ID
86
+
87
+ g .Go (func () error {
88
+ switch direction {
89
+ case fromService :
90
+ return s .copyFromContainer (ctx , containerID , srcPath , dstPath , opts )
91
+ case toService :
92
+ return s .copyToContainer (ctx , containerID , srcPath , dstPath , opts )
93
+ case acrossServices :
94
+ return errors .New ("copying between services is not supported" )
95
+ default :
96
+ return errors .New ("unknown copy direction" )
97
+ }
98
+ })
85
99
}
100
+
101
+ return g .Wait ()
86
102
}
87
103
88
104
func (s * composeService ) copyToContainer (ctx context.Context , containerID string , srcPath string , dstPath string , opts compose.CopyOptions ) error {
0 commit comments