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 <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2016-04-21 12:08:37 -04:00
parent e7e0837702
commit b90c048804
1 changed files with 6 additions and 0 deletions

View File

@ -59,6 +59,7 @@ type buildOptions struct {
compress bool compress bool
securityOpt []string securityOpt []string
networkMode string networkMode string
squash bool
} }
// NewBuildCommand creates a new `docker build` command // NewBuildCommand creates a new `docker build` command
@ -110,6 +111,10 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
command.AddTrustedFlags(flags, true) command.AddTrustedFlags(flags, true)
if dockerCli.HasExperimental() {
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
}
return cmd return cmd
} }
@ -305,6 +310,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
CacheFrom: options.cacheFrom, CacheFrom: options.cacheFrom,
SecurityOpt: options.securityOpt, SecurityOpt: options.securityOpt,
NetworkMode: options.networkMode, NetworkMode: options.networkMode,
Squash: options.squash,
} }
response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions) response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions)