MCPcopy
hub / github.com/docker/compose / attach

Method attach

pkg/compose/attach.go:36–64  ·  pkg/compose/attach.go::composeService.attach
(ctx context.Context, project *types.Project, listener api.ContainerEventListener, selectedServices []string)

Source from the content-addressed store, hash-verified

34)
35
36func (s *composeService) attach(ctx context.Context, project *types.Project, listener api.ContainerEventListener, selectedServices []string) (Containers, error) {
37 containers, err := s.getContainers(ctx, project.Name, oneOffExclude, true, selectedServices...)
38 if err != nil {
39 return nil, err
40 }
41 if len(containers) == 0 {
42 return containers, nil
43 }
44
45 containers.sorted() // This enforces predictable colors assignment
46
47 var names []string
48 for _, c := range containers {
49 names = append(names, getContainerNameWithoutProject(c))
50 }
51
52 _, err = fmt.Fprintf(s.stdout(), "Attaching to %s\n", strings.Join(names, ", "))
53 if err != nil {
54 logrus.Debugf("failed to write attach message: %v", err)
55 }
56
57 for _, ctr := range containers {
58 err := s.attachContainer(ctx, ctr, listener)
59 if err != nil {
60 return nil, err
61 }
62 }
63 return containers, nil
64}
65
66func (s *composeService) attachContainer(ctx context.Context, container containerType.Summary, listener api.ContainerEventListener) error {
67 service := container.Labels[api.ServiceLabel]

Callers 1

UpMethod · 0.95

Calls 5

getContainersMethod · 0.95
stdoutMethod · 0.95
attachContainerMethod · 0.95
sortedMethod · 0.80

Tested by

no test coverage detected