Skip to content

Commit 08ed2bc

Browse files
committed
cli/command/container: make injecting config.json failures a warning
Prior to 1a502e9, failing to write the container-ID to a file would return an error. After that change, we could end up in a situation where the container was created successfully, but we failed to inject the `config.json`. This failure would be returned as an error, but the container was created (but no ID returned due to the error). This patch changes the error to a warning; while not "ideal" (the container is created, but in a "partial" state), we also shouldn't consider it to be a hard failure; proceed as normal, to allow the user to either use the container as-is, or to delete the container and try again. Alternatively, we could join these errors, but the result will be ambiguous in either case (container created, but an error occurred after the fact). Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 0312e3d commit 08ed2bc

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

cli/command/container/create.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,22 +363,19 @@ func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *c
363363
}
364364
}
365365

366-
for _, w := range response.Warnings {
367-
_, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING:", w)
368-
}
369-
err = containerIDFile.Write(response.ID)
370-
371366
if options.useAPISocket && len(apiSocketCreds) > 0 {
372367
// Create a new config file with just the auth.
373-
newConfig := &configfile.ConfigFile{
368+
if err := copyDockerConfigIntoContainer(ctx, dockerCLI.Client(), response.ID, dockerConfigPathInContainer, &configfile.ConfigFile{
374369
AuthConfigs: apiSocketCreds,
375-
}
376-
377-
if err := copyDockerConfigIntoContainer(ctx, dockerCLI.Client(), response.ID, dockerConfigPathInContainer, newConfig); err != nil {
378-
return "", fmt.Errorf("injecting docker config.json into container failed: %w", err)
370+
}); err != nil {
371+
response.Warnings = append(response.Warnings, fmt.Sprintf("injecting docker config.json into container failed: %v", err))
379372
}
380373
}
374+
for _, w := range response.Warnings {
375+
_, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING:", w)
376+
}
381377

378+
err = containerIDFile.Write(response.ID)
382379
return response.ID, err
383380
}
384381

0 commit comments

Comments
 (0)