From b90c048804d3390f746fcceec9d7c43ba6570b74 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Thu, 21 Apr 2016 12:08:37 -0400 Subject: [PATCH] Adds ability to squash image after build Allow built images to be squash to scratch. Squashing does not destroy any images or layers, and preserves the build cache. Introduce a new CLI argument --squash to docker build Introduce a new param to the build API endpoint `squash` Once the build is complete, docker creates a new image loading the diffs from each layer into a single new layer and references all the parent's layers. Signed-off-by: Brian Goff --- command/image/build.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/command/image/build.go b/command/image/build.go index 7db76a649f..dc18601900 100644 --- a/command/image/build.go +++ b/command/image/build.go @@ -59,6 +59,7 @@ type buildOptions struct { compress bool securityOpt []string networkMode string + squash bool } // NewBuildCommand creates a new `docker build` command @@ -110,6 +111,10 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command { command.AddTrustedFlags(flags, true) + if dockerCli.HasExperimental() { + flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer") + } + return cmd } @@ -305,6 +310,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error { CacheFrom: options.cacheFrom, SecurityOpt: options.securityOpt, NetworkMode: options.networkMode, + Squash: options.squash, } response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)