diff --git a/cmd/compose/cp.go b/cmd/compose/cp.go index 9cd07e5f7..bd6281fc8 100644 --- a/cmd/compose/cp.go +++ b/cmd/compose/cp.go @@ -66,9 +66,7 @@ func copyCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) flags := copyCmd.Flags() flags.IntVar(&opts.index, "index", 0, "Index of the container if service has multiple replicas") - flags.BoolVar(&opts.all, "all", false, "Copy to all the containers of the service") - flags.MarkHidden("all") //nolint:errcheck - flags.MarkDeprecated("all", "By default all the containers of the service will get the source file/directory to be copied") //nolint:errcheck + flags.BoolVar(&opts.all, "all", false, "Include containers created by the run command") flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH") flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)") diff --git a/docs/reference/compose_cp.md b/docs/reference/compose_cp.md index 9ed14140e..0886bbd9f 100644 --- a/docs/reference/compose_cp.md +++ b/docs/reference/compose_cp.md @@ -7,6 +7,7 @@ Copy files/folders between a service container and the local filesystem | Name | Type | Default | Description | |:----------------------|:-------|:--------|:--------------------------------------------------------| +| `--all` | `bool` | | Include containers created by the run command | | `-a`, `--archive` | `bool` | | Archive mode (copy all uid/gid information) | | `--dry-run` | `bool` | | Execute command in dry run mode | | `-L`, `--follow-link` | `bool` | | Always follow symbol link in SRC_PATH | diff --git a/docs/reference/docker_compose_cp.yaml b/docs/reference/docker_compose_cp.yaml index 8ff3cf37e..24f6aec87 100644 --- a/docs/reference/docker_compose_cp.yaml +++ b/docs/reference/docker_compose_cp.yaml @@ -10,9 +10,9 @@ options: - option: all value_type: bool default_value: "false" - description: Copy to all the containers of the service - deprecated: true - hidden: true + description: Include containers created by the run command + deprecated: false + hidden: false experimental: false experimentalcli: false kubernetes: false diff --git a/pkg/compose/cp.go b/pkg/compose/cp.go index 107af78dd..f65e79196 100644 --- a/pkg/compose/cp.go +++ b/pkg/compose/cp.go @@ -61,11 +61,6 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a direction |= fromService serviceName = srcService copyFunc = s.copyFromContainer - - // copying from multiple containers of a services doesn't make sense. - if options.All { - return errors.New("cannot use the --all flag when copying from a service") - } } if destService != "" { direction |= toService @@ -80,7 +75,7 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a return errors.New("unknown copy direction") } - containers, err := s.listContainersTargetedForCopy(ctx, projectName, options.Index, direction, serviceName) + containers, err := s.listContainersTargetedForCopy(ctx, projectName, options, direction, serviceName) if err != nil { return err } @@ -119,18 +114,22 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a return g.Wait() } -func (s *composeService) listContainersTargetedForCopy(ctx context.Context, projectName string, index int, direction copyDirection, serviceName string) (Containers, error) { +func (s *composeService) listContainersTargetedForCopy(ctx context.Context, projectName string, options api.CopyOptions, direction copyDirection, serviceName string) (Containers, error) { var containers Containers var err error switch { - case index > 0: - ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, index) + case options.Index > 0: + ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, options.Index) if err != nil { return nil, err } return append(containers, ctr), nil default: - containers, err = s.getContainers(ctx, projectName, oneOffExclude, true, serviceName) + withOneOff := oneOffExclude + if options.All { + withOneOff = oneOffInclude + } + containers, err = s.getContainers(ctx, projectName, withOneOff, true, serviceName) if err != nil { return nil, err }