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

Method down

pkg/compose/down.go:44–125  ·  view source on GitHub ↗
(ctx context.Context, projectName string, options api.DownOptions)

Source from the content-addressed store, hash-verified

42}
43
44func (s *composeService) down(ctx context.Context, projectName string, options api.DownOptions) error { //nolint:gocyclo
45 resourceToRemove := false
46
47 include := oneOffExclude
48 if options.RemoveOrphans {
49 include = oneOffInclude
50 }
51 containers, err := s.getContainers(ctx, projectName, include, true)
52 if err != nil {
53 return err
54 }
55
56 project := options.Project
57 if project == nil {
58 project, err = s.getProjectWithResources(ctx, containers, projectName)
59 if err != nil {
60 return err
61 }
62 }
63
64 // Check requested services exists in model
65 services, err := checkSelectedServices(options, project)
66 if err != nil {
67 return err
68 }
69
70 if len(options.Services) > 0 && len(services) == 0 {
71 logrus.Infof("Any of the services %v not running in project %q", options.Services, projectName)
72 return nil
73 }
74
75 options.Services = services
76
77 if len(containers) > 0 {
78 resourceToRemove = true
79 }
80
81 err = InReverseDependencyOrder(ctx, project, func(c context.Context, service string) error {
82 serv := project.Services[service]
83 if serv.Provider != nil {
84 return s.runPlugin(ctx, project, serv, "down")
85 }
86 serviceContainers := containers.filter(isService(service))
87 err := s.removeContainers(ctx, serviceContainers, &serv, options.Timeout, options.Volumes)
88 return err
89 }, WithRootNodesAndDown(options.Services))
90 if err != nil {
91 return err
92 }
93
94 orphans := containers.filter(isOrphaned(project))
95 if options.RemoveOrphans && len(orphans) > 0 {
96 err := s.removeContainers(ctx, orphans, nil, options.Timeout, false)
97 if err != nil {
98 return err
99 }
100 }
101

Callers 1

DownMethod · 0.95

Calls 14

getContainersMethod · 0.95
runPluginMethod · 0.95
removeContainersMethod · 0.95
ensureNetworksDownMethod · 0.95
ensureImagesDownMethod · 0.95
ensureVolumesDownMethod · 0.95
checkSelectedServicesFunction · 0.85
InReverseDependencyOrderFunction · 0.85
isServiceFunction · 0.85
WithRootNodesAndDownFunction · 0.85
isOrphanedFunction · 0.85

Tested by

no test coverage detected