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 committed by Tibor Vass
parent 44edbbdbc2
commit e34679982f
2 changed files with 35 additions and 0 deletions

View File

@ -54,6 +54,7 @@ Options:
The format is `<number><unit>`. `number` must be greater than `0`. The format is `<number><unit>`. `number` must be greater than `0`.
Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes),
or `g` (gigabytes). If you omit the unit, the system uses bytes. or `g` (gigabytes). If you omit the unit, the system uses bytes.
--squash Squash newly built layers into a single new layer (**Experimental Only**)
-t, --tag value Name and optionally a tag in the 'name:tag' format (default []) -t, --tag value Name and optionally a tag in the 'name:tag' format (default [])
--ulimit value Ulimit options (default []) --ulimit value Ulimit options (default [])
``` ```
@ -432,3 +433,20 @@ Linux namespaces. On Microsoft Windows, you can specify these values:
| `hyperv` | Hyper-V hypervisor partition-based isolation. | | `hyperv` | Hyper-V hypervisor partition-based isolation. |
Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`. Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`.
### Squash an image's layers (--squash) **Experimental Only**
Once the image is built, squash the new layers into a new image with a single
new layer. Squashing does not destroy any existing image, rather it creates a new
image with the content of the squshed layers. This effectively makes it look
like all `Dockerfile` commands were created with a single layer. The build
cache is preserved with this method.
**Note**: using this option means the new image will not be able to take
advantage of layer sharing with other images and may use significantly more
space.
**Note**: using this option you may see significantly more space used due to
storing two copies of the image, one for the build cache with all the cache
layers in tact, and one for the squashed version.

View File

@ -11,6 +11,7 @@ docker-build - Build a new image from the source code at PATH
[**--cgroup-parent**[=*CGROUP-PARENT*]] [**--cgroup-parent**[=*CGROUP-PARENT*]]
[**--help**] [**--help**]
[**-f**|**--file**[=*PATH/Dockerfile*]] [**-f**|**--file**[=*PATH/Dockerfile*]]
[**-squash**] *Experimental*
[**--force-rm**] [**--force-rm**]
[**--isolation**[=*default*]] [**--isolation**[=*default*]]
[**--label**[=*[]*]] [**--label**[=*[]*]]
@ -57,6 +58,22 @@ set as the **URL**, the repository is cloned locally and then sent as the contex
the remote context. In all cases, the file must be within the build context. the remote context. In all cases, the file must be within the build context.
The default is *Dockerfile*. The default is *Dockerfile*.
**--squash**=*true*|*false*
**Experimental Only**
Once the image is built, squash the new layers into a new image with a single
new layer. Squashing does not destroy any existing image, rather it creates a new
image with the content of the squshed layers. This effectively makes it look
like all `Dockerfile` commands were created with a single layer. The build
cache is preserved with this method.
**Note**: using this option means the new image will not be able to take
advantage of layer sharing with other images and may use significantly more
space.
**Note**: using this option you may see significantly more space used due to
storing two copies of the image, one for the build cache with all the cache
layers in tact, and one for the squashed version.
**--build-arg**=*variable* **--build-arg**=*variable*
name and value of a **buildarg**. name and value of a **buildarg**.