MCPcopy Index your code
hub / github.com/ddev/ddev / FindContainerByName

Function FindContainerByName

pkg/dockerutil/containers.go:152–177  ·  view source on GitHub ↗

FindContainerByName takes a container name and returns the container If container is not found, returns nil with no error

(name string)

Source from the content-addressed store, hash-verified

150// FindContainerByName takes a container name and returns the container
151// If container is not found, returns nil with no error
152func FindContainerByName(name string) (*container.Summary, error) {
153 ctx, apiClient, err := GetDockerClient()
154 if err != nil {
155 return nil, err
156 }
157
158 containers, err := apiClient.ContainerList(ctx, client.ContainerListOptions{
159 All: true,
160 Filters: client.Filters{}.Add("name", name),
161 })
162 if err != nil {
163 return nil, err
164 }
165 if len(containers.Items) == 0 {
166 return nil, nil
167 }
168
169 // ListContainers can return partial matches. Make sure we only match the exact one
170 // we're after.
171 for _, c := range containers.Items {
172 if len(c.Names) > 0 && c.Names[0] == "/"+name {
173 return &c, nil
174 }
175 }
176 return nil, nil
177}
178
179// GetContainerStateByName returns container state for the named container
180func GetContainerStateByName(name string) (container.ContainerState, error) {

Callers 15

IsXHGuiContainerRunningFunction · 0.92
TestDdevExecFunction · 0.92
GetErrLogsFromAppFunction · 0.92
IsMutagenVolumeMountedFunction · 0.92
StartMethod · 0.92
GetContainerFunction · 0.92
TestFindContainerByNameFunction · 0.92
TestCopyIntoContainerFunction · 0.92
TestCopyFromContainerFunction · 0.92
TestComposeWithStreamsFunction · 0.92
ContainerCheckFunction · 0.92
TestCmdStopFunction · 0.92

Calls 1

GetDockerClientFunction · 0.85

Tested by 8

TestDdevExecFunction · 0.74
TestFindContainerByNameFunction · 0.74
TestCopyIntoContainerFunction · 0.74
TestCopyFromContainerFunction · 0.74
TestComposeWithStreamsFunction · 0.74
TestCmdStopFunction · 0.74
TestPoweroffOnNewVersionFunction · 0.74