MCPcopy
hub / github.com/containerd/containerd / NewContainer

Method NewContainer

client/client.go:340–377  ·  view source on GitHub ↗

NewContainer will create a new container with the provided id. The id must be unique within the namespace.

(ctx context.Context, id string, opts ...NewContainerOpts)

Source from the content-addressed store, hash-verified

338// NewContainer will create a new container with the provided id.
339// The id must be unique within the namespace.
340func (c *Client) NewContainer(ctx context.Context, id string, opts ...NewContainerOpts) (Container, error) {
341 ctx, span := tracing.StartSpan(ctx, "client.NewContainer")
342 defer span.End()
343 ctx, done, err := c.WithLease(ctx)
344 if err != nil {
345 return nil, err
346 }
347 defer done(ctx)
348
349 runtime, err := c.defaultRuntime(ctx)
350 if err != nil {
351 return nil, err
352 }
353
354 container := containers.Container{
355 ID: id,
356 Runtime: containers.RuntimeInfo{
357 Name: runtime,
358 },
359 }
360 for _, o := range opts {
361 if err := o(ctx, c, &container); err != nil {
362 return nil, err
363 }
364 }
365
366 span.SetAttributes(
367 tracing.Attribute("container.id", container.ID),
368 tracing.Attribute("container.image.ref", container.Image),
369 tracing.Attribute("container.runtime.name", container.Runtime.Name),
370 tracing.Attribute("container.snapshotter.name", container.Snapshotter),
371 )
372 r, err := c.ContainerService().Create(ctx, container)
373 if err != nil {
374 return nil, err
375 }
376 return containerFromRecord(c, r), nil
377}
378
379// LoadContainer loads an existing container from metadata
380func (c *Client) LoadContainer(ctx context.Context, id string) (Container, error) {

Callers 1

RestoreMethod · 0.95

Calls 9

WithLeaseMethod · 0.95
defaultRuntimeMethod · 0.95
ContainerServiceMethod · 0.95
StartSpanFunction · 0.92
AttributeFunction · 0.92
containerFromRecordFunction · 0.85
EndMethod · 0.80
SetAttributesMethod · 0.80
CreateMethod · 0.65

Tested by

no test coverage detected