build: Don't unpack by default when pushing

Automatically set `unpack=false` for registry exports unless explicitly
overridden by the user.

This applies to:

- `registry` exporter type (converted to `image` exporter with `push=true`)
- `--push` flag usage with image exporters

Users can still explicitly set `unpack=true` if they need local image
storage alongside registry push.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2026-01-14 16:04:45 +01:00
parent e33272c855
commit 41a1782b35
6 changed files with 89 additions and 4 deletions
+7 -1
View File
@@ -542,7 +542,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugger debuggerOpt
flags.StringArrayVar(&options.platforms, "platform", platformsDefault, "Set target platform for build")
flags.BoolVar(&options.exportPush, "push", false, `Shorthand for "--output=type=registry"`)
flags.BoolVar(&options.exportPush, "push", false, `Shorthand for "--output=type=registry,unpack=false"`)
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Suppress the build output and print image ID on success")
@@ -1048,6 +1048,10 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *BuildOptions, inSt
for i := range outputs {
if outputs[i].Type == client.ExporterImage {
outputs[i].Attrs["push"] = "true"
// Skip unpacking when only pushing to registry (unless explicitly set)
if _, ok := outputs[i].Attrs["unpack"]; !ok {
outputs[i].Attrs["unpack"] = "false"
}
pushUsed = true
}
}
@@ -1056,6 +1060,8 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *BuildOptions, inSt
Type: client.ExporterImage,
Attrs: map[string]string{
"push": "true",
// Skip unpacking when only pushing to registry
"unpack": "false",
},
})
}