MCPcopy Create free account
hub / github.com/containerd/nerdctl / composeContainerPrintableTab

Function composeContainerPrintableTab

cmd/nerdctl/compose/compose_ps.go:237–275  ·  view source on GitHub ↗

composeContainerPrintableTab constructs composeContainerPrintable with fields only for console output.

(ctx context.Context, container containerd.Container, gOptions types.GlobalCommandOptions)

Source from the content-addressed store, hash-verified

235// composeContainerPrintableTab constructs composeContainerPrintable with fields
236// only for console output.
237func composeContainerPrintableTab(ctx context.Context, container containerd.Container, gOptions types.GlobalCommandOptions) (composeContainerPrintable, error) {
238 info, err := container.Info(ctx, containerd.WithoutRefreshedMetadata)
239 if err != nil {
240 return composeContainerPrintable{}, err
241 }
242 spec, err := container.Spec(ctx)
243 if err != nil {
244 return composeContainerPrintable{}, err
245 }
246 status := formatter.ContainerStatus(ctx, container)
247 if status == "Up" {
248 status = "running" // corresponds to Docker Compose v2.0.1
249 }
250 image, err := container.Image(ctx)
251 if err != nil {
252 return composeContainerPrintable{}, err
253 }
254 dataStore, err := clientutil.DataStore(gOptions.DataRoot, gOptions.Address)
255 if err != nil {
256 return composeContainerPrintable{}, err
257 }
258 containerLabels, err := container.Labels(ctx)
259 if err != nil {
260 return composeContainerPrintable{}, err
261 }
262 ports, err := portutil.LoadPortMappings(dataStore, gOptions.Namespace, info.ID, containerLabels)
263 if err != nil {
264 return composeContainerPrintable{}, err
265 }
266
267 return composeContainerPrintable{
268 Name: info.Labels[labels.Name],
269 Image: image.Metadata().Name,
270 Command: formatter.InspectContainerCommandTrunc(spec),
271 Service: info.Labels[labels.ComposeService],
272 State: status,
273 Ports: formatter.FormatPorts(ports),
274 }, nil
275}
276
277// composeContainerPrintableJSON constructs composeContainerPrintable with fields
278// only for json output and compatible docker output.

Callers 1

psActionFunction · 0.85

Calls 7

ContainerStatusFunction · 0.92
DataStoreFunction · 0.92
LoadPortMappingsFunction · 0.92
FormatPortsFunction · 0.92
InfoMethod · 0.80
LabelsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…