Browse code

Merge pull request #30974 from erxian/add-new-cli-argument-squash-to-docker-build

add docs to describe experimental CLI argument --squash to docker build

Sebastiaan van Stijn authored on 2017/03/28 00:09:54
Showing 2 changed files
... ...
@@ -444,6 +444,8 @@ more `--add-host` flags. This example adds a static address for a host named
444 444
 
445 445
 ### Squash an image's layers (--squash) **Experimental Only**
446 446
 
447
+#### Overview
448
+
447 449
 Once the image is built, squash the new layers into a new image with a single
448 450
 new layer. Squashing does not destroy any existing image, rather it creates a new
449 451
 image with the content of the squashed layers. This effectively makes it look
... ...
@@ -458,3 +460,91 @@ space.
458 458
 storing two copies of the image, one for the build cache with all the cache
459 459
 layers in tact, and one for the squashed version.
460 460
 
461
+#### Prerequisites
462
+
463
+The example on this page is using experimental mode in Docker 1.13.
464
+
465
+Experimental mode can be enabled by using the `--experimental` flag when starting the Docker daemon or setting `experimental: true` in the `daemon.json` configuration file.
466
+
467
+By default, experimental mode is disabled. To see the current configuration, use the `docker version` command.
468
+
469
+```none
470
+
471
+Server:
472
+ Version:      1.13.1
473
+ API version:  1.26 (minimum version 1.12)
474
+ Go version:   go1.7.5
475
+ Git commit:   092cba3
476
+ Built:        Wed Feb  8 06:35:24 2017
477
+ OS/Arch:      linux/amd64
478
+ Experimental: false
479
+
480
+ [...]
481
+
482
+```
483
+
484
+To enable experimental mode, users need to restart the docker daemon with the experimental flag enabled.
485
+
486
+#### Enable Docker experimental
487
+
488
+Experimental features are now included in the standard Docker binaries as of version 1.13.0. For enabling experimental features, you need to start the Docker daemon with `--experimental` flag. You can also enable the daemon flag via /etc/docker/daemon.json. e.g.
489
+
490
+```
491
+
492
+{
493
+    "experimental": true
494
+}
495
+
496
+```
497
+Then make sure the experimental flag is enabled:
498
+
499
+```bash
500
+
501
+$ docker version -f '{{.Server.Experimental}}'
502
+true
503
+
504
+```
505
+
506
+#### Build an image with `--squash` argument
507
+
508
+The following is an example of docker build with `--squash` argument
509
+
510
+```Dockerfile
511
+
512
+FROM busybox
513
+RUN echo hello > /hello
514
+RUN echo world >> /hello
515
+RUN touch remove_me /remove_me
516
+ENV HELLO world
517
+RUN rm /remove_me
518
+
519
+```
520
+An image named `test` is built with `--squash` argument.
521
+
522
+```bash
523
+
524
+$ docker build --squash -t test .
525
+
526
+[...]
527
+
528
+```
529
+
530
+If everything is right, the history will look like this:
531
+
532
+```bash
533
+$ docker history test 
534
+
535
+IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
536
+4e10cb5b4cac        3 seconds ago                                                       12 B                merge sha256:88a7b0112a41826885df0e7072698006ee8f621c6ab99fca7fe9151d7b599702 to sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb
537
+<missing>           5 minutes ago       /bin/sh -c rm /remove_me                        0 B
538
+<missing>           5 minutes ago       /bin/sh -c #(nop) ENV HELLO=world               0 B
539
+<missing>           5 minutes ago       /bin/sh -c touch remove_me /remove_me           0 B
540
+<missing>           5 minutes ago       /bin/sh -c echo world >> /hello                 0 B
541
+<missing>           6 minutes ago       /bin/sh -c echo hello > /hello                  0 B
542
+<missing>           7 weeks ago         /bin/sh -c #(nop) CMD ["sh"]                    0 B
543
+<missing>           7 weeks ago         /bin/sh -c #(nop) ADD file:47ca6e777c36a4cfff   1.113 MB
544
+
545
+```
546
+We could find that all layer's name is `<missing>`, and there is a new layer with COMMENT `merge`.
547
+
548
+Test the image, check for `/remove_me` being gone, make sure `hello\nworld` is in `/hello`, make sure the `HELLO` envvar's value is `world`.
... ...
@@ -36,6 +36,7 @@ true
36 36
  * [Ipvlan Network Drivers](vlan-networks.md)
37 37
  * [Docker Stacks and Distributed Application Bundles](docker-stacks-and-bundles.md)
38 38
  * [Checkpoint & Restore](checkpoint-restore.md)
39
+ * [Docker build with --squash argument](docker-build-with-squash.md)
39 40
 
40 41
 ## How to comment on an experimental feature
41 42