github.com/itscaro/cli@v0.0.0-20190705081621-c9db0fe93829/docs/reference/commandline/build.md (about)

     1  ---
     2  title: "build"
     3  description: "The build command description and usage"
     4  keywords: "build, docker, image"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/cli GitHub
     8       repository at https://github.com/docker/cli/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # build
    17  
    18  ```markdown
    19  Usage:  docker build [OPTIONS] PATH | URL | -
    20  
    21  Build an image from a Dockerfile
    22  
    23  Options:
    24        --add-host value          Add a custom host-to-IP mapping (host:ip) (default [])
    25        --build-arg value         Set build-time variables (default [])
    26        --cache-from value        Images to consider as cache sources (default [])
    27        --cgroup-parent string    Optional parent cgroup for the container
    28        --compress                Compress the build context using gzip
    29        --cpu-period int          Limit the CPU CFS (Completely Fair Scheduler) period
    30        --cpu-quota int           Limit the CPU CFS (Completely Fair Scheduler) quota
    31    -c, --cpu-shares int          CPU shares (relative weight)
    32        --cpuset-cpus string      CPUs in which to allow execution (0-3, 0,1)
    33        --cpuset-mems string      MEMs in which to allow execution (0-3, 0,1)
    34        --disable-content-trust   Skip image verification (default true)
    35    -f, --file string             Name of the Dockerfile (Default is 'PATH/Dockerfile')
    36        --force-rm                Always remove intermediate containers
    37        --help                    Print usage
    38        --iidfile string          Write the image ID to the file
    39        --isolation string        Container isolation technology
    40        --label value             Set metadata for an image (default [])
    41    -m, --memory string           Memory limit
    42        --memory-swap string      Swap limit equal to memory plus swap: '-1' to enable unlimited swap
    43        --network string          Set the networking mode for the RUN instructions during build
    44                                  'bridge': use default Docker bridge
    45                                  'none': no networking
    46                                  'container:<name|id>': reuse another container's network stack
    47                                  'host': use the Docker host network stack
    48                                  '<network-name>|<network-id>': connect to a user-defined network
    49        --no-cache                Do not use cache when building the image
    50        --pull                    Always attempt to pull a newer version of the image
    51        --progress                Set type of progress output (only if BuildKit enabled) (auto, plain, tty). 
    52                                  Use plain to show container output
    53    -q, --quiet                   Suppress the build output and print image ID on success
    54        --rm                      Remove intermediate containers after a successful build (default true)
    55        --secret                  Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret"
    56        --security-opt value      Security Options (default [])
    57        --shm-size bytes          Size of /dev/shm
    58                                  The format is `<number><unit>`. `number` must be greater than `0`.
    59                                  Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes),
    60                                  or `g` (gigabytes). If you omit the unit, the system uses bytes.
    61        --squash                  Squash newly built layers into a single new layer (**Experimental Only**)
    62        --ssh                     SSH agent socket or keys to expose to the build (only if BuildKit enabled) (format: default|<id>[=<socket>|<key>[,<key>]])
    63    -t, --tag value               Name and optionally a tag in the 'name:tag' format (default [])
    64        --target string           Set the target build stage to build.
    65        --ulimit value            Ulimit options (default [])
    66  ```
    67  
    68  ## Description
    69  
    70  The `docker build` command builds Docker images from a Dockerfile and a
    71  "context". A build's context is the set of files located in the specified
    72  `PATH` or `URL`. The build process can refer to any of the files in the
    73  context. For example, your build can use a [*COPY*](../builder.md#copy)
    74  instruction to reference a file in the context.
    75  
    76  The `URL` parameter can refer to three kinds of resources: Git repositories,
    77  pre-packaged tarball contexts and plain text files.
    78  
    79  ### Git repositories
    80  
    81  When the `URL` parameter points to the location of a Git repository, the
    82  repository acts as the build context. The system recursively fetches the
    83  repository and its submodules. The commit history is not preserved. A
    84  repository is first pulled into a temporary directory on your local host. After
    85  that succeeds, the directory is sent to the Docker daemon as the context.
    86  Local copy gives you the ability to access private repositories using local
    87  user credentials, VPN's, and so forth.
    88  
    89  > **Note:**
    90  > If the `URL` parameter contains a fragment the system will recursively clone
    91  > the repository and its submodules using a `git clone --recursive` command.
    92  
    93  Git URLs accept context configuration in their fragment section, separated by a
    94  colon `:`.  The first part represents the reference that Git will check out,
    95  and can be either a branch, a tag, or a remote reference. The second part
    96  represents a subdirectory inside the repository that will be used as a build
    97  context.
    98  
    99  For example, run this command to use a directory called `docker` in the branch
   100  `container`:
   101  
   102  ```bash
   103  $ docker build https://github.com/docker/rootfs.git#container:docker
   104  ```
   105  
   106  The following table represents all the valid suffixes with their build
   107  contexts:
   108  
   109  Build Syntax Suffix             | Commit Used           | Build Context Used
   110  --------------------------------|-----------------------|-------------------
   111  `myrepo.git`                    | `refs/heads/master`   | `/`
   112  `myrepo.git#mytag`              | `refs/tags/mytag`     | `/`
   113  `myrepo.git#mybranch`           | `refs/heads/mybranch` | `/`
   114  `myrepo.git#pull/42/head`       | `refs/pull/42/head`   | `/`
   115  `myrepo.git#:myfolder`          | `refs/heads/master`   | `/myfolder`
   116  `myrepo.git#master:myfolder`    | `refs/heads/master`   | `/myfolder`
   117  `myrepo.git#mytag:myfolder`     | `refs/tags/mytag`     | `/myfolder`
   118  `myrepo.git#mybranch:myfolder`  | `refs/heads/mybranch` | `/myfolder`
   119  
   120  
   121  ### Tarball contexts
   122  
   123  If you pass an URL to a remote tarball, the URL itself is sent to the daemon:
   124  
   125  ```bash
   126  $ docker build http://server/context.tar.gz
   127  ```
   128  
   129  The download operation will be performed on the host the Docker daemon is
   130  running on, which is not necessarily the same host from which the build command
   131  is being issued. The Docker daemon will fetch `context.tar.gz` and use it as the
   132  build context. Tarball contexts must be tar archives conforming to the standard
   133  `tar` UNIX format and can be compressed with any one of the 'xz', 'bzip2',
   134  'gzip' or 'identity' (no compression) formats.
   135  
   136  ### Text files
   137  
   138  Instead of specifying a context, you can pass a single `Dockerfile` in the
   139  `URL` or pipe the file in via `STDIN`. To pipe a `Dockerfile` from `STDIN`:
   140  
   141  ```bash
   142  $ docker build - < Dockerfile
   143  ```
   144  
   145  With Powershell on Windows, you can run:
   146  
   147  ```powershell
   148  Get-Content Dockerfile | docker build -
   149  ```
   150  
   151  If you use `STDIN` or specify a `URL` pointing to a plain text file, the system
   152  places the contents into a file called `Dockerfile`, and any `-f`, `--file`
   153  option is ignored. In this scenario, there is no context.
   154  
   155  By default the `docker build` command will look for a `Dockerfile` at the root
   156  of the build context. The `-f`, `--file`, option lets you specify the path to
   157  an alternative file to use instead. This is useful in cases where the same set
   158  of files are used for multiple builds. The path must be to a file within the
   159  build context. If a relative path is specified then it is interpreted as
   160  relative to the root of the context.
   161  
   162  In most cases, it's best to put each Dockerfile in an empty directory. Then,
   163  add to that directory only the files needed for building the Dockerfile. To
   164  increase the build's performance, you can exclude files and directories by
   165  adding a `.dockerignore` file to that directory as well. For information on
   166  creating one, see the [.dockerignore file](../builder.md#dockerignore-file).
   167  
   168  If the Docker client loses connection to the daemon, the build is canceled.
   169  This happens if you interrupt the Docker client with `CTRL-c` or if the Docker
   170  client is killed for any reason. If the build initiated a pull which is still
   171  running at the time the build is cancelled, the pull is cancelled as well.
   172  
   173  ## Return code
   174  
   175  On a successful build, a return code of success `0` will be returned.  When the
   176  build fails, a non-zero failure code will be returned.
   177  
   178  There should be informational output of the reason for failure output to
   179  `STDERR`:
   180  
   181  ```bash
   182  $ docker build -t fail .
   183  
   184  Sending build context to Docker daemon 2.048 kB
   185  Sending build context to Docker daemon
   186  Step 1/3 : FROM busybox
   187   ---> 4986bf8c1536
   188  Step 2/3 : RUN exit 13
   189   ---> Running in e26670ec7a0a
   190  INFO[0000] The command [/bin/sh -c exit 13] returned a non-zero code: 13
   191  $ echo $?
   192  1
   193  ```
   194  
   195  See also:
   196  
   197  [*Dockerfile Reference*](../builder.md).
   198  
   199  ## Examples
   200  
   201  ### Build with PATH
   202  
   203  ```bash
   204  $ docker build .
   205  
   206  Uploading context 10240 bytes
   207  Step 1/3 : FROM busybox
   208  Pulling repository busybox
   209   ---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/
   210  Step 2/3 : RUN ls -lh /
   211   ---> Running in 9c9e81692ae9
   212  total 24
   213  drwxr-xr-x    2 root     root        4.0K Mar 12  2013 bin
   214  drwxr-xr-x    5 root     root        4.0K Oct 19 00:19 dev
   215  drwxr-xr-x    2 root     root        4.0K Oct 19 00:19 etc
   216  drwxr-xr-x    2 root     root        4.0K Nov 15 23:34 lib
   217  lrwxrwxrwx    1 root     root           3 Mar 12  2013 lib64 -> lib
   218  dr-xr-xr-x  116 root     root           0 Nov 15 23:34 proc
   219  lrwxrwxrwx    1 root     root           3 Mar 12  2013 sbin -> bin
   220  dr-xr-xr-x   13 root     root           0 Nov 15 23:34 sys
   221  drwxr-xr-x    2 root     root        4.0K Mar 12  2013 tmp
   222  drwxr-xr-x    2 root     root        4.0K Nov 15 23:34 usr
   223   ---> b35f4035db3f
   224  Step 3/3 : CMD echo Hello world
   225   ---> Running in 02071fceb21b
   226   ---> f52f38b7823e
   227  Successfully built f52f38b7823e
   228  Removing intermediate container 9c9e81692ae9
   229  Removing intermediate container 02071fceb21b
   230  ```
   231  
   232  This example specifies that the `PATH` is `.`, and so all the files in the
   233  local directory get `tar`d and sent to the Docker daemon. The `PATH` specifies
   234  where to find the files for the "context" of the build on the Docker daemon.
   235  Remember that the daemon could be running on a remote machine and that no
   236  parsing of the Dockerfile happens at the client side (where you're running
   237  `docker build`). That means that *all* the files at `PATH` get sent, not just
   238  the ones listed to [*ADD*](../builder.md#add) in the Dockerfile.
   239  
   240  The transfer of context from the local machine to the Docker daemon is what the
   241  `docker` client means when you see the "Sending build context" message.
   242  
   243  If you wish to keep the intermediate containers after the build is complete,
   244  you must use `--rm=false`. This does not affect the build cache.
   245  
   246  ### Build with URL
   247  
   248  ```bash
   249  $ docker build github.com/creack/docker-firefox
   250  ```
   251  
   252  This will clone the GitHub repository and use the cloned repository as context.
   253  The Dockerfile at the root of the repository is used as Dockerfile. You can
   254  specify an arbitrary Git repository by using the `git://` or `git@` scheme.
   255  
   256  ```bash
   257  $ docker build -f ctx/Dockerfile http://server/ctx.tar.gz
   258  
   259  Downloading context: http://server/ctx.tar.gz [===================>]    240 B/240 B
   260  Step 1/3 : FROM busybox
   261   ---> 8c2e06607696
   262  Step 2/3 : ADD ctx/container.cfg /
   263   ---> e7829950cee3
   264  Removing intermediate container b35224abf821
   265  Step 3/3 : CMD /bin/ls
   266   ---> Running in fbc63d321d73
   267   ---> 3286931702ad
   268  Removing intermediate container fbc63d321d73
   269  Successfully built 377c409b35e4
   270  ```
   271  
   272  This sends the URL `http://server/ctx.tar.gz` to the Docker daemon, which
   273  downloads and extracts the referenced tarball. The `-f ctx/Dockerfile`
   274  parameter specifies a path inside `ctx.tar.gz` to the `Dockerfile` that is used
   275  to build the image. Any `ADD` commands in that `Dockerfile` that refers to local
   276  paths must be relative to the root of the contents inside `ctx.tar.gz`. In the
   277  example above, the tarball contains a directory `ctx/`, so the `ADD
   278  ctx/container.cfg /` operation works as expected.
   279  
   280  ### Build with -
   281  
   282  ```bash
   283  $ docker build - < Dockerfile
   284  ```
   285  
   286  This will read a Dockerfile from `STDIN` without context. Due to the lack of a
   287  context, no contents of any local directory will be sent to the Docker daemon.
   288  Since there is no context, a Dockerfile `ADD` only works if it refers to a
   289  remote URL.
   290  
   291  ```bash
   292  $ docker build - < context.tar.gz
   293  ```
   294  
   295  This will build an image for a compressed context read from `STDIN`.  Supported
   296  formats are: bzip2, gzip and xz.
   297  
   298  ### Use a .dockerignore file
   299  
   300  ```bash
   301  $ docker build .
   302  
   303  Uploading context 18.829 MB
   304  Uploading context
   305  Step 1/2 : FROM busybox
   306   ---> 769b9341d937
   307  Step 2/2 : CMD echo Hello world
   308   ---> Using cache
   309   ---> 99cc1ad10469
   310  Successfully built 99cc1ad10469
   311  $ echo ".git" > .dockerignore
   312  $ docker build .
   313  Uploading context  6.76 MB
   314  Uploading context
   315  Step 1/2 : FROM busybox
   316   ---> 769b9341d937
   317  Step 2/2 : CMD echo Hello world
   318   ---> Using cache
   319   ---> 99cc1ad10469
   320  Successfully built 99cc1ad10469
   321  ```
   322  
   323  This example shows the use of the `.dockerignore` file to exclude the `.git`
   324  directory from the context. Its effect can be seen in the changed size of the
   325  uploaded context. The builder reference contains detailed information on
   326  [creating a .dockerignore file](../builder.md#dockerignore-file)
   327  
   328  ### Tag an image (-t)
   329  
   330  ```bash
   331  $ docker build -t vieux/apache:2.0 .
   332  ```
   333  
   334  This will build like the previous example, but it will then tag the resulting
   335  image. The repository name will be `vieux/apache` and the tag will be `2.0`.
   336  [Read more about valid tags](tag.md).
   337  
   338  You can apply multiple tags to an image. For example, you can apply the `latest`
   339  tag to a newly built image and add another tag that references a specific
   340  version.
   341  For example, to tag an image both as `whenry/fedora-jboss:latest` and
   342  `whenry/fedora-jboss:v2.1`, use the following:
   343  
   344  ```bash
   345  $ docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 .
   346  ```
   347  
   348  ### Specify a Dockerfile (-f)
   349  
   350  ```bash
   351  $ docker build -f Dockerfile.debug .
   352  ```
   353  
   354  This will use a file called `Dockerfile.debug` for the build instructions
   355  instead of `Dockerfile`.
   356  
   357  ```bash
   358  $ curl example.com/remote/Dockerfile | docker build -f - .
   359  ```
   360  
   361  The above command will use the current directory as the build context and read
   362  a Dockerfile from stdin.
   363  
   364  ```bash
   365  $ docker build -f dockerfiles/Dockerfile.debug -t myapp_debug .
   366  $ docker build -f dockerfiles/Dockerfile.prod  -t myapp_prod .
   367  ```
   368  
   369  The above commands will build the current build context (as specified by the
   370  `.`) twice, once using a debug version of a `Dockerfile` and once using a
   371  production version.
   372  
   373  ```bash
   374  $ cd /home/me/myapp/some/dir/really/deep
   375  $ docker build -f /home/me/myapp/dockerfiles/debug /home/me/myapp
   376  $ docker build -f ../../../../dockerfiles/debug /home/me/myapp
   377  ```
   378  
   379  These two `docker build` commands do the exact same thing. They both use the
   380  contents of the `debug` file instead of looking for a `Dockerfile` and will use
   381  `/home/me/myapp` as the root of the build context. Note that `debug` is in the
   382  directory structure of the build context, regardless of how you refer to it on
   383  the command line.
   384  
   385  > **Note:**
   386  > `docker build` will return a `no such file or directory` error if the
   387  > file or directory does not exist in the uploaded context. This may
   388  > happen if there is no context, or if you specify a file that is
   389  > elsewhere on the Host system. The context is limited to the current
   390  > directory (and its children) for security reasons, and to ensure
   391  > repeatable builds on remote Docker hosts. This is also the reason why
   392  > `ADD ../file` will not work.
   393  
   394  ### Use a custom parent cgroup (--cgroup-parent)
   395  
   396  When `docker build` is run with the `--cgroup-parent` option the containers
   397  used in the build will be run with the [corresponding `docker run`
   398  flag](../run.md#specifying-custom-cgroups).
   399  
   400  ### Set ulimits in container (--ulimit)
   401  
   402  Using the `--ulimit` option with `docker build` will cause each build step's
   403  container to be started using those [`--ulimit`
   404  flag values](./run.md#set-ulimits-in-container-ulimit).
   405  
   406  ### Set build-time variables (--build-arg)
   407  
   408  You can use `ENV` instructions in a Dockerfile to define variable
   409  values. These values persist in the built image. However, often
   410  persistence is not what you want. Users want to specify variables differently
   411  depending on which host they build an image on.
   412  
   413  A good example is `http_proxy` or source versions for pulling intermediate
   414  files. The `ARG` instruction lets Dockerfile authors define values that users
   415  can set at build-time using the  `--build-arg` flag:
   416  
   417  ```bash
   418  $ docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 --build-arg FTP_PROXY=http://40.50.60.5:4567 .
   419  ```
   420  
   421  This flag allows you to pass the build-time variables that are
   422  accessed like regular environment variables in the `RUN` instruction of the
   423  Dockerfile. Also, these values don't persist in the intermediate or final images
   424  like `ENV` values do.   You must add `--build-arg` for each build argument.  
   425  
   426  Using this flag will not alter the output you see when the `ARG` lines from the
   427  Dockerfile are echoed during the build process.
   428  
   429  For detailed information on using `ARG` and `ENV` instructions, see the
   430  [Dockerfile reference](../builder.md).
   431  
   432  You may also use the `--build-arg` flag without a value, in which case the value
   433  from the local environment will be propagated into the Docker container being
   434  built:
   435  
   436  ```bash
   437  $ export HTTP_PROXY=http://10.20.30.2:1234
   438  $ docker build --build-arg HTTP_PROXY .
   439  ```
   440  
   441  This is similar to how `docker run -e` works. Refer to the [`docker run` documentation](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file)
   442  for more information.
   443  
   444  ### Optional security options (--security-opt)
   445  
   446  This flag is only supported on a daemon running on Windows, and only supports
   447  the `credentialspec` option. The `credentialspec` must be in the format
   448  `file://spec.txt` or `registry://keyname`.
   449  
   450  ### Specify isolation technology for container (--isolation)
   451  
   452  This option is useful in situations where you are running Docker containers on
   453  Windows. The `--isolation=<value>` option sets a container's isolation
   454  technology. On Linux, the only supported is the `default` option which uses
   455  Linux namespaces. On Microsoft Windows, you can specify these values:
   456  
   457  
   458  | Value     | Description                                                                                                                                                   |
   459  |-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
   460  | `default` | Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value.  |
   461  | `process` | Namespace isolation only.                                                                                                                                     |
   462  | `hyperv`  | Hyper-V hypervisor partition-based isolation.                                                                                                                 |
   463  
   464  Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`.
   465  
   466  ### Add entries to container hosts file (--add-host)
   467  
   468  You can add other hosts into a container's `/etc/hosts` file by using one or
   469  more `--add-host` flags. This example adds a static address for a host named
   470  `docker`:
   471  
   472      $ docker build --add-host=docker:10.180.0.1 .
   473  
   474  ### Specifying target build stage (--target)
   475  
   476  When building a Dockerfile with multiple build stages, `--target` can be used to
   477  specify an intermediate build stage by name as a final stage for the resulting
   478  image. Commands after the target stage will be skipped.
   479  
   480  ```Dockerfile
   481  FROM debian AS build-env
   482  ...
   483  
   484  FROM alpine AS production-env
   485  ...
   486  ```
   487  
   488  ```bash
   489  $ docker build -t mybuildimage --target build-env .
   490  ```
   491  
   492  ### Squash an image's layers (--squash) (experimental)
   493  
   494  #### Overview
   495  
   496  Once the image is built, squash the new layers into a new image with a single
   497  new layer. Squashing does not destroy any existing image, rather it creates a new
   498  image with the content of the squashed layers. This effectively makes it look
   499  like all `Dockerfile` commands were created with a single layer. The build
   500  cache is preserved with this method.
   501  
   502  The `--squash` option is an experimental feature, and should not be considered
   503  stable.
   504  
   505  
   506  Squashing layers can be beneficial if your Dockerfile produces multiple layers
   507  modifying the same files, for example, files that are created in one step, and
   508  removed in another step. For other use-cases, squashing images may actually have
   509  a negative impact on performance; when pulling an image consisting of multiple
   510  layers, layers can be pulled in parallel, and allows sharing layers between
   511  images (saving space).
   512  
   513  For most use cases, multi-stage builds are a better alternative, as they give more
   514  fine-grained control over your build, and can take advantage of future
   515  optimizations in the builder. Refer to the [use multi-stage builds](https://docs.docker.com/develop/develop-images/multistage-build/)
   516  section in the userguide for more information.
   517  
   518  
   519  #### Known limitations
   520  
   521  The `--squash` option has a number of known limitations:
   522  
   523  - When squashing layers, the resulting image cannot take advantage of layer
   524    sharing with other images, and may use significantly more space. Sharing the
   525    base image is still supported.
   526  - When using this option you may see significantly more space used due to
   527    storing two copies of the image, one for the build cache with all the cache
   528    layers in tact, and one for the squashed version.
   529  - While squashing layers may produce smaller images, it may have a negative
   530    impact on performance, as a single layer takes longer to extract, and
   531    downloading a single layer cannot be parallelized.
   532  - When attempting to squash an image that does not make changes to the
   533    filesystem (for example, the Dockerfile only contains `ENV` instructions),
   534    the squash step will fail (see [issue #33823](https://github.com/moby/moby/issues/33823)).
   535  
   536  #### Prerequisites
   537  
   538  The example on this page is using experimental mode in Docker 1.13.
   539  
   540  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.
   541  
   542  By default, experimental mode is disabled. To see the current configuration, use the `docker version` command.
   543  
   544  ```none
   545  Server:
   546   Version:      1.13.1
   547   API version:  1.26 (minimum version 1.12)
   548   Go version:   go1.7.5
   549   Git commit:   092cba3
   550   Built:        Wed Feb  8 06:35:24 2017
   551   OS/Arch:      linux/amd64
   552   Experimental: false
   553  
   554   [...]
   555  ```
   556  
   557  To enable experimental mode, users need to restart the docker daemon with the experimental flag enabled.
   558  
   559  #### Enable Docker experimental
   560  
   561  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.
   562  
   563  ```json
   564  {
   565      "experimental": true
   566  }
   567  ```
   568  
   569  Then make sure the experimental flag is enabled:
   570  
   571  ```bash
   572  $ docker version -f '{{.Server.Experimental}}'
   573  true
   574  ```
   575  
   576  #### Build an image with `--squash` argument
   577  
   578  The following is an example of docker build with `--squash` argument
   579  
   580  ```Dockerfile
   581  FROM busybox
   582  RUN echo hello > /hello
   583  RUN echo world >> /hello
   584  RUN touch remove_me /remove_me
   585  ENV HELLO world
   586  RUN rm /remove_me
   587  ```
   588  
   589  An image named `test` is built with `--squash` argument.
   590  
   591  ```bash
   592  $ docker build --squash -t test .
   593  
   594  [...]
   595  ```
   596  
   597  If everything is right, the history will look like this:
   598  
   599  ```bash
   600  $ docker history test
   601  
   602  IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
   603  4e10cb5b4cac        3 seconds ago                                                       12 B                merge sha256:88a7b0112a41826885df0e7072698006ee8f621c6ab99fca7fe9151d7b599702 to sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb
   604  <missing>           5 minutes ago       /bin/sh -c rm /remove_me                        0 B
   605  <missing>           5 minutes ago       /bin/sh -c #(nop) ENV HELLO=world               0 B
   606  <missing>           5 minutes ago       /bin/sh -c touch remove_me /remove_me           0 B
   607  <missing>           5 minutes ago       /bin/sh -c echo world >> /hello                 0 B
   608  <missing>           6 minutes ago       /bin/sh -c echo hello > /hello                  0 B
   609  <missing>           7 weeks ago         /bin/sh -c #(nop) CMD ["sh"]                    0 B
   610  <missing>           7 weeks ago         /bin/sh -c #(nop) ADD file:47ca6e777c36a4cfff   1.113 MB
   611  ```
   612  
   613  We could find that all layer's name is `<missing>`, and there is a new layer with COMMENT `merge`.
   614  
   615  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`.