MCPcopy
hub / github.com/containers/toolbox / createContainer

Function createContainer

src/cmd/create.go:190–508  ·  view source on GitHub ↗
(container, image, release, authFile string, showCommandToEnter bool)

Source from the content-addressed store, hash-verified

188}
189
190func createContainer(container, image, release, authFile string, showCommandToEnter bool) error {
191 if container == "" {
192 panic("container not specified")
193 }
194
195 if image == "" {
196 panic("image not specified")
197 }
198
199 if release == "" {
200 panic("release not specified")
201 }
202
203 enterCommand := getEnterCommand(container)
204
205 logrus.Debugf("Checking if container %s already exists", container)
206
207 if exists, _ := podman.ContainerExists(container); exists {
208 var builder strings.Builder
209 fmt.Fprintf(&builder, "container %s already exists\n", container)
210 fmt.Fprintf(&builder, "Enter with: %s\n", enterCommand)
211 fmt.Fprintf(&builder, "Run '%s --help' for usage.", executableBase)
212
213 errMsg := builder.String()
214 return errors.New(errMsg)
215 }
216
217 pulled, err := pullImage(image, release, authFile)
218 if err != nil {
219 return err
220 }
221 if !pulled {
222 return nil
223 }
224
225 imageFull, err := podman.GetFullyQualifiedImageFromRepoTags(image)
226 if err != nil {
227 var errImage *podman.ImageError
228
229 if errors.As(err, &errImage) {
230 if errors.Is(err, podman.ErrImageRepoTagsEmpty) {
231 logrus.Debugf("Image %s has empty RepoTags, likely because it is without a name", image)
232 imageFull = image
233 } else if errors.Is(err, podman.ErrImageRepoTagsMissing) {
234 return fmt.Errorf("missing RepoTags for image %s", image)
235 } else {
236 panicMsg := fmt.Sprintf("unexpected %T: %s", err, err)
237 panic(panicMsg)
238 }
239 } else {
240 return err
241 }
242 }
243
244 var toolbxDelayEntryPointEnv []string
245
246 if toolbxDelayEntryPoint, ok := os.LookupEnv("TOOLBX_DELAY_ENTRY_POINT"); ok {
247 toolbxDelayEntryPointEnvArg := "TOOLBX_DELAY_ENTRY_POINT=" + toolbxDelayEntryPoint

Callers 2

runCommandFunction · 0.85
createFunction · 0.85

Calls 6

getEnterCommandFunction · 0.85
pullImageFunction · 0.85
getDBusSystemSocketFunction · 0.85
getCurrentUserHomeDirFunction · 0.85
getServiceSocketFunction · 0.85
IsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…