MCPcopy
hub / github.com/determined-ai/determined / CreateContainer

Method CreateContainer

agent/pkg/docker/docker.go:244–286  ·  view source on GitHub ↗

CreateContainer creates a container according to the given spec, returning a docker container ID to start it. It takes a caller-provided channel on which docker events are sent. Slow receivers will block the call.

(
	ctx context.Context,
	id cproto.ID,
	req cproto.RunSpec,
	p events.Publisher[Event],
)

Source from the content-addressed store, hash-verified

242// to start it. It takes a caller-provided channel on which docker events are sent. Slow receivers
243// will block the call.
244func (d *Client) CreateContainer(
245 ctx context.Context,
246 id cproto.ID,
247 req cproto.RunSpec,
248 p events.Publisher[Event],
249) (string, error) {
250 response, err := d.cl.ContainerCreate(
251 ctx, &req.ContainerConfig, &req.HostConfig, &req.NetworkingConfig, nil, "")
252 if err != nil {
253 return "", fmt.Errorf("creating container: %w", err)
254 }
255 dockerID := response.ID
256 for _, w := range response.Warnings {
257 if err = p.Publish(ctx, NewLogEvent(model.LogLevelWarning, fmt.Sprintf(
258 "warning when creating container: %s", w,
259 ))); err != nil {
260 return "", err
261 }
262 }
263
264 for _, copyArx := range req.Archives {
265 if err = p.Publish(ctx, NewLogEvent(model.LogLevelInfo, fmt.Sprintf(
266 "copying files to container: %s", copyArx.Path,
267 ))); err != nil {
268 return "", err
269 }
270
271 files, cErr := archive.ToIOReader(copyArx.Archive)
272 if cErr != nil {
273 return "", fmt.Errorf("converting RunSpec Archive files to io.Reader: %w", cErr)
274 }
275 if err = d.cl.CopyToContainer(
276 ctx,
277 dockerID,
278 copyArx.Path,
279 files,
280 copyArx.CopyOptions,
281 ); err != nil {
282 return "", fmt.Errorf("copying files to container: %w", err)
283 }
284 }
285 return dockerID, nil
286}
287
288// RunContainer runs a container by docker container ID. It takes a caller-provided channel on which
289// docker events are sent. Slow receivers will block the call. RunContainer takes two contexts: one

Callers 2

TestRunContainerFunction · 0.95

Calls 4

ToIOReaderFunction · 0.92
NewLogEventFunction · 0.85
PublishMethod · 0.65
ErrorfMethod · 0.45

Tested by 2

TestRunContainerFunction · 0.76