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

Method execCreateContainer

pkg/compose/executor_ops.go:71–120  ·  pkg/compose/executor_ops.go::planExecutor.execCreateContainer

--- Container operations ---

(ctx context.Context, node *PlanNode)

Source from the content-addressed store, hash-verified

69// --- Container operations ---
70
71func (exec *planExecutor) execCreateContainer(ctx context.Context, node *PlanNode) error {
72 op := node.Operation
73 service := *op.Service
74 // Detach VolumesFrom from the source slice: resolveServiceReferences mutates
75 // entries in place, and the shallow struct copy still shares the backing array.
76 service.VolumesFrom = slices.Clone(op.Service.VolumesFrom)
77
78 // Resolve service references (network_mode, ipc, pid, volumes_from) to
79 // actual container IDs from the in-memory view, which already includes
80 // any containers created by earlier plan nodes.
81 exec.containersMu.Lock()
82 err := resolveServiceReferences(&service, exec.containersByService)
83 exec.containersMu.Unlock()
84 if err != nil {
85 return err
86 }
87
88 labels := mergeLabels(service.Labels, service.CustomLabels)
89 if op.Inherited != nil {
90 // This is a recreate: add the replace label
91 replacedName := op.Service.ContainerName
92 if replacedName == "" {
93 replacedName = fmt.Sprintf("%s%s%d", op.Service.Name, api.Separator, op.Number)
94 }
95 labels = labels.Add(api.ContainerReplaceLabel, replacedName)
96 }
97
98 opts := createOptions{
99 AutoRemove: false,
100 AttachStdin: false,
101 UseNetworkAliases: true,
102 Labels: labels,
103 }
104 ctr, err := exec.compose.createMobyContainer(ctx, exec.project, service, op.Name, op.Number, op.Inherited, opts)
105 if err != nil {
106 return err
107 }
108
109 exec.pctx.set(node.ID, operationResult{
110 ContainerID: ctr.ID,
111 ContainerName: op.Name,
112 })
113
114 // Make the new container visible to subsequent execCreateContainer calls
115 // that resolve service references against op.Service.Name.
116 exec.containersMu.Lock()
117 exec.containersByService[op.Service.Name] = append(exec.containersByService[op.Service.Name], ctr)
118 exec.containersMu.Unlock()
119 return nil
120}
121
122func (exec *planExecutor) execStartContainer(ctx context.Context, op Operation) error {
123 startMx.Lock()

Callers 1

executeNodeMethod · 0.95

Calls 6

resolveServiceReferencesFunction · 0.85
mergeLabelsFunction · 0.85
createMobyContainerMethod · 0.80
setMethod · 0.80
LockMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected