From effdf1b45229fab8a1ddf9e8004db37ff3e602f1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 24 Jan 2026 14:05:56 +0100 Subject: [PATCH 1/5] cli/command/container: rename vars to use correct camelCase Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 3c773e1a47..d070d8d15f 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -212,7 +212,7 @@ func newCIDFile(cidPath string) (*cidFile, error) { } //nolint:gocyclo -func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *containerConfig, options *createOptions) (containerID string, err error) { +func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *containerConfig, options *createOptions) (containerID string, err error) { config := containerCfg.Config hostConfig := containerCfg.HostConfig networkingConfig := containerCfg.NetworkingConfig @@ -251,7 +251,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c // 1. Mount the actual docker socket. // 2. A synthezised ~/.docker/config.json with resolved tokens. - if dockerCli.ServerInfo().OSType == "windows" { + if dockerCLI.ServerInfo().OSType == "windows" { return "", errors.New("flag --use-api-socket can't be used with a Windows Docker Engine") } @@ -286,18 +286,18 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c }) */ - var envvarPresent bool - for _, envvar := range containerCfg.Config.Env { - if strings.HasPrefix(envvar, "DOCKER_CONFIG=") { - envvarPresent = true + var envVarPresent bool + for _, envVar := range containerCfg.Config.Env { + if strings.HasPrefix(envVar, "DOCKER_CONFIG=") { + envVarPresent = true } } // If the DOCKER_CONFIG env var is already present, we assume the client knows // what they're doing and don't inject the creds. - if !envvarPresent { + if !envVarPresent { // Resolve this here for later, ensuring we error our before we create the container. - creds, err := readCredentials(dockerCli) + creds, err := readCredentials(dockerCLI) if err != nil { return "", fmt.Errorf("resolving credentials failed: %w", err) } @@ -320,7 +320,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c } pullAndTagImage := func() error { - if err := pullImage(ctx, dockerCli, config.Image, options); err != nil { + if err := pullImage(ctx, dockerCLI, config.Image, options); err != nil { return err } return nil @@ -332,9 +332,9 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c } } - hostConfig.ConsoleSize[0], hostConfig.ConsoleSize[1] = dockerCli.Out().GetTtySize() + hostConfig.ConsoleSize[0], hostConfig.ConsoleSize[1] = dockerCLI.Out().GetTtySize() - response, err := dockerCli.Client().ContainerCreate(ctx, client.ContainerCreateOptions{ + response, err := dockerCLI.Client().ContainerCreate(ctx, client.ContainerCreateOptions{ Name: options.name, // Image: config.Image, // TODO(thaJeztah): pass image-ref separate Platform: platform, @@ -347,7 +347,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c if errdefs.IsNotFound(err) && namedRef != nil && options.pull == PullImageMissing { if !options.quiet { // we don't want to write to stdout anything apart from container.ID - _, _ = fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef)) + _, _ = fmt.Fprintf(dockerCLI.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef)) } if err := pullAndTagImage(); err != nil { @@ -355,7 +355,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c } var retryErr error - response, retryErr = dockerCli.Client().ContainerCreate(ctx, client.ContainerCreateOptions{ + response, retryErr = dockerCLI.Client().ContainerCreate(ctx, client.ContainerCreateOptions{ Name: options.name, // Image: config.Image, // TODO(thaJeztah): pass image-ref separate Platform: platform, @@ -373,7 +373,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c containerID = response.ID for _, w := range response.Warnings { - _, _ = fmt.Fprintln(dockerCli.Err(), "WARNING:", w) + _, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING:", w) } err = containerIDFile.Write(containerID) @@ -383,7 +383,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c AuthConfigs: apiSocketCreds, } - if err := copyDockerConfigIntoContainer(ctx, dockerCli.Client(), containerID, dockerConfigPathInContainer, newConfig); err != nil { + if err := copyDockerConfigIntoContainer(ctx, dockerCLI.Client(), containerID, dockerConfigPathInContainer, newConfig); err != nil { return "", fmt.Errorf("injecting docker config.json into container failed: %w", err) } } From ceea57b46d9a47db76e57139caca16899db07c62 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 24 Jan 2026 14:07:41 +0100 Subject: [PATCH 2/5] cli/command/container: copyDockerConfigIntoContainer: close TarWriter Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/command/container/create.go b/cli/command/container/create.go index d070d8d15f..f70e474338 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -428,6 +428,7 @@ func copyDockerConfigIntoContainer(ctx context.Context, apiClient client.APIClie }) if _, err := io.Copy(tarWriter, &configBuf); err != nil { + _ = tarWriter.Close() return fmt.Errorf("writing config to tar file for config copy: %w", err) } From adfb40ceb1a8b0a18e5fad95f14b03f3f01e9961 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 24 Jan 2026 14:12:34 +0100 Subject: [PATCH 3/5] cli/command/container: remove outdated TODO This was addressed in 7bdb4df07da0d6f5046f6073213d30c4973420c4 Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/command/container/create.go b/cli/command/container/create.go index f70e474338..0ac03c1bbe 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -132,7 +132,6 @@ func runCreate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, return nil } -// FIXME(thaJeztah): this is the only code-path that uses APIClient.ImageCreate. Rewrite this to use the regular "pull" code (or vice-versa). func pullImage(ctx context.Context, dockerCLI command.Cli, img string, options *createOptions) error { encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCLI.ConfigFile(), img) if err != nil { From cfb71de7dbc90fac46077ce0e05e97b3d61bf733 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 24 Jan 2026 14:17:05 +0100 Subject: [PATCH 4/5] cli/command/container: createContainer: remove redundant closure Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 0ac03c1bbe..932e77c603 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -318,15 +318,8 @@ func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *c platform = &p } - pullAndTagImage := func() error { - if err := pullImage(ctx, dockerCLI, config.Image, options); err != nil { - return err - } - return nil - } - if options.pull == PullImageAlways { - if err := pullAndTagImage(); err != nil { + if err := pullImage(ctx, dockerCLI, config.Image, options); err != nil { return "", err } } @@ -349,7 +342,7 @@ func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *c _, _ = fmt.Fprintf(dockerCLI.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef)) } - if err := pullAndTagImage(); err != nil { + if err := pullImage(ctx, dockerCLI, config.Image, options); err != nil { return "", err } From ed566e723f9af8bcf350bc2eda79ee5fe73069c0 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 24 Jan 2026 14:33:06 +0100 Subject: [PATCH 5/5] cli/command/container: createContainer: remove intermediate vars Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 932e77c603..4dab997018 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -211,7 +211,7 @@ func newCIDFile(cidPath string) (*cidFile, error) { } //nolint:gocyclo -func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *containerConfig, options *createOptions) (containerID string, err error) { +func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *containerConfig, options *createOptions) (containerID string, _ error) { config := containerCfg.Config hostConfig := containerCfg.HostConfig networkingConfig := containerCfg.NetworkingConfig @@ -220,8 +220,7 @@ func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *c // TODO(thaJeztah): add a platform option-type / flag-type. if options.platform != "" { - _, err = platforms.Parse(options.platform) - if err != nil { + if _, err := platforms.Parse(options.platform); err != nil { return "", err } } @@ -247,8 +246,9 @@ func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *c if options.useAPISocket { // We'll create two new mounts to handle this flag: + // // 1. Mount the actual docker socket. - // 2. A synthezised ~/.docker/config.json with resolved tokens. + // 2. A synthesized ~/.docker/config.json with resolved tokens. if dockerCLI.ServerInfo().OSType == "windows" { return "", errors.New("flag --use-api-socket can't be used with a Windows Docker Engine") @@ -363,11 +363,10 @@ func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *c } } - containerID = response.ID for _, w := range response.Warnings { _, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING:", w) } - err = containerIDFile.Write(containerID) + err = containerIDFile.Write(response.ID) if options.useAPISocket && len(apiSocketCreds) > 0 { // Create a new config file with just the auth. @@ -375,12 +374,12 @@ func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *c AuthConfigs: apiSocketCreds, } - if err := copyDockerConfigIntoContainer(ctx, dockerCLI.Client(), containerID, dockerConfigPathInContainer, newConfig); err != nil { + if err := copyDockerConfigIntoContainer(ctx, dockerCLI.Client(), response.ID, dockerConfigPathInContainer, newConfig); err != nil { return "", fmt.Errorf("injecting docker config.json into container failed: %w", err) } } - return containerID, err + return response.ID, err } func validatePullOpt(val string) error {