(ctx context.Context, daemonCfg *configStore, opts createOpts)
| 65 | } |
| 66 | |
| 67 | func (daemon *Daemon) containerCreate(ctx context.Context, daemonCfg *configStore, opts createOpts) (_ containertypes.CreateResponse, retErr error) { |
| 68 | ctx, span := otel.Tracer("").Start(ctx, "daemon.containerCreate", trace.WithAttributes( |
| 69 | labelsAsOTelAttributes(opts.params.Config.Labels)..., |
| 70 | )) |
| 71 | defer func() { |
| 72 | otelutil.RecordStatus(span, retErr) |
| 73 | span.End() |
| 74 | }() |
| 75 | |
| 76 | start := time.Now() |
| 77 | if opts.params.Config == nil { |
| 78 | return containertypes.CreateResponse{}, errdefs.InvalidParameter(errors.New("config cannot be empty in order to create a container")) |
| 79 | } |
| 80 | |
| 81 | // Normalize some defaults. Doing this "ad-hoc" here for now, as there's |
| 82 | // only one field to migrate, but we should consider having a better |
| 83 | // location for this (and decide where in the flow would be most appropriate). |
| 84 | // |
| 85 | // TODO(thaJeztah): we should have a more visible, more canonical location for this. |
| 86 | if opts.params.HostConfig != nil && opts.params.HostConfig.RestartPolicy.Name == "" { |
| 87 | // Set the default restart-policy ("none") if no restart-policy was set. |
| 88 | opts.params.HostConfig.RestartPolicy.Name = containertypes.RestartPolicyDisabled |
| 89 | } |
| 90 | |
| 91 | warnings, err := daemon.verifyContainerSettings(daemonCfg, opts.params.HostConfig, opts.params.Config, false) |
| 92 | if err != nil { |
| 93 | return containertypes.CreateResponse{Warnings: warnings}, errdefs.InvalidParameter(err) |
| 94 | } |
| 95 | |
| 96 | if opts.params.Platform == nil && opts.params.Config.Image != "" { |
| 97 | img, err := daemon.imageService.GetImage(ctx, opts.params.Config.Image, imagebackend.GetImageOpts{}) |
| 98 | if err != nil { |
| 99 | return containertypes.CreateResponse{}, err |
| 100 | } |
| 101 | if img != nil { |
| 102 | p := maximumSpec() |
| 103 | imgPlat := ocispec.Platform{ |
| 104 | OS: img.OS, |
| 105 | Architecture: img.Architecture, |
| 106 | Variant: img.Variant, |
| 107 | } |
| 108 | |
| 109 | if !images.OnlyPlatformWithFallback(p).Match(imgPlat) { |
| 110 | warnings = append(warnings, fmt.Sprintf("The requested image's platform (%s) does not match the detected host platform (%s) and no specific platform was requested", platforms.FormatAll(imgPlat), platforms.FormatAll(p))) |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | err = daemon.validateNetworkingConfig(opts.params.NetworkingConfig) |
| 116 | if err != nil { |
| 117 | return containertypes.CreateResponse{Warnings: warnings}, errdefs.InvalidParameter(err) |
| 118 | } |
| 119 | |
| 120 | if opts.params.HostConfig == nil { |
| 121 | opts.params.HostConfig = &containertypes.HostConfig{} |
| 122 | } |
| 123 | err = daemon.adaptContainerSettings(&daemonCfg.Config, opts.params.HostConfig) |
| 124 | if err != nil { |
no test coverage detected