github.com/endocode/docker@v1.4.2-0.20160113120958-46eb4700391e/docs/reference/builder.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "Dockerfile reference"
     4  description = "Dockerfiles use a simple DSL which allows you to automate the steps you would normally manually take to create an image."
     5  keywords = ["builder, docker, Dockerfile, automation,  image creation"]
     6  [menu.main]
     7  parent = "mn_reference"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # Dockerfile reference
    12  
    13  Docker can build images automatically by reading the instructions from a
    14  `Dockerfile`. A `Dockerfile` is a text document that contains all the commands a
    15  user could call on the command line to assemble an image. Using `docker build`
    16  users can create an automated build that executes several command-line
    17  instructions in succession.
    18  
    19  This page describes the commands you can use in a `Dockerfile`. When you are
    20  done reading this page, refer to the [`Dockerfile` Best
    21  Practices](../articles/dockerfile_best-practices.md) for a tip-oriented guide.
    22  
    23  ## Usage
    24  
    25  The [`docker build`](commandline/build.md) command builds an image from
    26  a `Dockerfile` and a *context*. The build's context is the files at a specified
    27  location `PATH` or `URL`. The `PATH` is a directory on your local filesystem.
    28  The `URL` is a the location of a Git repository.
    29  
    30  A context is processed recursively. So, a `PATH` includes any subdirectories and
    31  the `URL` includes the repository and its submodules. A simple build command
    32  that uses the current directory as context:
    33  
    34      $ docker build .
    35      Sending build context to Docker daemon  6.51 MB
    36      ...
    37  
    38  The build is run by the Docker daemon, not by the CLI. The first thing a build
    39  process does is send the entire context (recursively) to the daemon.  In most
    40  cases, it's best to start with an empty directory as context and keep your
    41  Dockerfile in that directory. Add only the files needed for building the
    42  Dockerfile.
    43  
    44  >**Warning**: Do not use your root directory, `/`, as the `PATH` as it causes
    45  >the build to transfer the entire contents of your hard drive to the Docker
    46  >daemon.
    47  
    48  To use a file in the build context, the `Dockerfile` refers to the file specified
    49  in an instruction, for example,  a `COPY` instruction. To increase the build's
    50  performance, exclude files and directories by adding a `.dockerignore` file to
    51  the context directory.  For information about how to [create a `.dockerignore`
    52  file](#dockerignore-file) see the documentation on this page.
    53  
    54  Traditionally, the `Dockerfile` is called `Dockerfile` and located in the root
    55  of the context. You use the `-f` flag with `docker build` to point to a Dockerfile
    56  anywhere in your file system.
    57  
    58      $ docker build -f /path/to/a/Dockerfile .
    59  
    60  You can specify a repository and tag at which to save the new image if
    61  the build succeeds:
    62  
    63      $ docker build -t shykes/myapp .
    64  
    65  To tag the image into multiple repositories after the build,
    66  add multiple `-t` parameters when you run the `build` command:
    67  
    68      $ docker build -t shykes/myapp:1.0.2 -t shykes/myapp:latest .
    69  
    70  The Docker daemon runs the instructions in the `Dockerfile` one-by-one,
    71  committing the result of each instruction
    72  to a new image if necessary, before finally outputting the ID of your
    73  new image. The Docker daemon will automatically clean up the context you
    74  sent.
    75  
    76  Note that each instruction is run independently, and causes a new image
    77  to be created - so `RUN cd /tmp` will not have any effect on the next
    78  instructions.
    79  
    80  Whenever possible, Docker will re-use the intermediate images (cache),
    81  to accelerate the `docker build` process significantly. This is indicated by
    82  the `Using cache` message in the console output.
    83  (For more information, see the [Build cache section](../articles/dockerfile_best-practices.md#build-cache)) in the
    84  `Dockerfile` best practices guide:
    85  
    86      $ docker build -t svendowideit/ambassador .
    87      Sending build context to Docker daemon 15.36 kB
    88      Step 0 : FROM alpine:3.2
    89       ---> 31f630c65071
    90      Step 1 : MAINTAINER SvenDowideit@home.org.au
    91       ---> Using cache
    92       ---> 2a1c91448f5f
    93      Step 2 : RUN apk update &&      apk add socat &&        rm -r /var/cache/
    94       ---> Using cache
    95       ---> 21ed6e7fbb73
    96      Step 3 : CMD env | grep _TCP= | (sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat -t 100000000 TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/' && echo wait) | sh
    97       ---> Using cache
    98       ---> 7ea8aef582cc
    99      Successfully built 7ea8aef582cc
   100  
   101  When you're done with your build, you're ready to look into [*Pushing a
   102  repository to its registry*](../userguide/dockerrepos.md#contributing-to-docker-hub).
   103  
   104  ## Format
   105  
   106  Here is the format of the `Dockerfile`:
   107  
   108      # Comment
   109      INSTRUCTION arguments
   110  
   111  The instruction is not case-sensitive, however convention is for them to
   112  be UPPERCASE in order to distinguish them from arguments more easily.
   113  
   114  Docker runs the instructions in a `Dockerfile` in order. **The
   115  first instruction must be \`FROM\`** in order to specify the [*Base
   116  Image*](glossary.md#base-image) from which you are building.
   117  
   118  Docker will treat lines that *begin* with `#` as a
   119  comment. A `#` marker anywhere else in the line will
   120  be treated as an argument. This allows statements like:
   121  
   122      # Comment
   123      RUN echo 'we are running some # of cool things'
   124  
   125  Here is the set of instructions you can use in a `Dockerfile` for building
   126  images.
   127  
   128  ### Environment replacement
   129  
   130  Environment variables (declared with [the `ENV` statement](#env)) can also be
   131  used in certain instructions as variables to be interpreted by the
   132  `Dockerfile`. Escapes are also handled for including variable-like syntax
   133  into a statement literally.
   134  
   135  Environment variables are notated in the `Dockerfile` either with
   136  `$variable_name` or `${variable_name}`. They are treated equivalently and the
   137  brace syntax is typically used to address issues with variable names with no
   138  whitespace, like `${foo}_bar`.
   139  
   140  The `${variable_name}` syntax also supports a few of the standard `bash`
   141  modifiers as specified below:
   142  
   143  * `${variable:-word}` indicates that if `variable` is set then the result
   144    will be that value. If `variable` is not set then `word` will be the result.
   145  * `${variable:+word}` indicates that if `variable` is set then `word` will be
   146    the result, otherwise the result is the empty string.
   147  
   148  In all cases, `word` can be any string, including additional environment
   149  variables.
   150  
   151  Escaping is possible by adding a `\` before the variable: `\$foo` or `\${foo}`,
   152  for example, will translate to `$foo` and `${foo}` literals respectively.
   153  
   154  Example (parsed representation is displayed after the `#`):
   155  
   156      FROM busybox
   157      ENV foo /bar
   158      WORKDIR ${foo}   # WORKDIR /bar
   159      ADD . $foo       # ADD . /bar
   160      COPY \$foo /quux # COPY $foo /quux
   161  
   162  Environment variables are supported by the following list of instructions in
   163  the `Dockerfile`:
   164  
   165  * `ADD`
   166  * `COPY`
   167  * `ENV`
   168  * `EXPOSE`
   169  * `LABEL`
   170  * `USER`
   171  * `WORKDIR`
   172  * `VOLUME`
   173  * `STOPSIGNAL`
   174  
   175  as well as:
   176  
   177  * `ONBUILD` (when combined with one of the supported instructions above)
   178  
   179  > **Note**:
   180  > prior to 1.4, `ONBUILD` instructions did **NOT** support environment
   181  > variable, even when combined with any of the instructions listed above.
   182  
   183  Environment variable substitution will use the same value for each variable
   184  throughout the entire command. In other words, in this example:
   185  
   186      ENV abc=hello
   187      ENV abc=bye def=$abc
   188      ENV ghi=$abc
   189  
   190  will result in `def` having a value of `hello`, not `bye`. However,
   191  `ghi` will have a value of `bye` because it is not part of the same command
   192  that set `abc` to `bye`.
   193  
   194  ### .dockerignore file
   195  
   196  Before the docker CLI sends the context to the docker daemon, it looks
   197  for a file named `.dockerignore` in the root directory of the context.
   198  If this file exists, the CLI modifies the context to exclude files and
   199  directories that match patterns in it.  This helps to avoid
   200  unnecessarily sending large or sensitive files and directories to the
   201  daemon and potentially adding them to images using `ADD` or `COPY`.
   202  
   203  The CLI interprets the `.dockerignore` file as a newline-separated
   204  list of patterns similar to the file globs of Unix shells.  For the
   205  purposes of matching, the root of the context is considered to be both
   206  the working and the root directory.  For example, the patterns
   207  `/foo/bar` and `foo/bar` both exclude a file or directory named `bar`
   208  in the `foo` subdirectory of `PATH` or in the root of the git
   209  repository located at `URL`.  Neither excludes anything else.
   210  
   211  Here is an example `.dockerignore` file:
   212  
   213  ```
   214      */temp*
   215      */*/temp*
   216      temp?
   217  ```
   218  
   219  This file causes the following build behavior:
   220  
   221  | Rule           | Behavior                                                                                                                                                                     |
   222  |----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
   223  | `*/temp*`      | Exclude files and directories whose names start with `temp` in any immediate subdirectory of the root.  For example, the plain file `/somedir/temporary.txt` is excluded, as is the directory `/somedir/temp`.                 |
   224  | `*/*/temp*`    | Exclude files and directories starting with `temp` from any subdirectory that is two levels below the root. For example, `/somedir/subdir/temporary.txt` is excluded. |
   225  | `temp?`        | Exclude files and directories in the root directory whose names are a one-character extension of `temp`.  For example, `/tempa` and `/tempb` are excluded.
   226  
   227  
   228  Matching is done using Go's
   229  [filepath.Match](http://golang.org/pkg/path/filepath#Match) rules.  A
   230  preprocessing step removes leading and trailing whitespace and
   231  eliminates `.` and `..` elements using Go's
   232  [filepath.Clean](http://golang.org/pkg/path/filepath/#Clean).  Lines
   233  that are blank after preprocessing are ignored.
   234  
   235  Beyond Go's filepath.Match rules, Docker also supports a special
   236  wildcard string `**` that matches any number of directories (including
   237  zero). For example, `**/*.go` will exclude all files that end with `.go`
   238  that are found in all directories, including the root of the build context.
   239  
   240  Lines starting with `!` (exclamation mark) can be used to make exceptions
   241  to exclusions.  The following is an example `.dockerignore` file that
   242  uses this mechanism:
   243  
   244  ```
   245      *.md
   246      !README.md
   247  ```
   248  
   249  All markdown files *except* `README.md` are excluded from the context.
   250  
   251  The placement of `!` exception rules influences the behavior: the last
   252  line of the `.dockerignore` that matches a particular file determines
   253  whether it is included or excluded.  Consider the following example:
   254  
   255  ```
   256      *.md
   257      !README*.md
   258      README-secret.md
   259  ```
   260  
   261  No markdown files are included in the context except README files other than
   262  `README-secret.md`.
   263  
   264  Now consider this example:
   265  
   266  ```
   267      *.md
   268      README-secret.md
   269      !README*.md
   270  ```
   271  
   272  All of the README files are included.  The middle line has no effect because
   273  `!README*.md` matches `README-secret.md` and comes last.
   274  
   275  You can even use the `.dockerignore` file to exclude the `Dockerfile`
   276  and `.dockerignore` files.  These files are still sent to the daemon
   277  because it needs them to do its job.  But the `ADD` and `COPY` commands
   278  do not copy them to the the image.
   279  
   280  Finally, you may want to specify which files to include in the
   281  context, rather than which to exclude. To achieve this, specify `*` as
   282  the first pattern, followed by one or more `!` exception patterns.
   283  
   284  **Note**: For historical reasons, the pattern `.` is ignored.
   285  
   286  ## FROM
   287  
   288      FROM <image>
   289  
   290  Or
   291  
   292      FROM <image>:<tag>
   293  
   294  Or
   295  
   296      FROM <image>@<digest>
   297  
   298  The `FROM` instruction sets the [*Base Image*](glossary.md#base-image)
   299  for subsequent instructions. As such, a valid `Dockerfile` must have `FROM` as
   300  its first instruction. The image can be any valid image – it is especially easy
   301  to start by **pulling an image** from the [*Public Repositories*](../userguide/dockerrepos.md).
   302  
   303  - `FROM` must be the first non-comment instruction in the `Dockerfile`.
   304  
   305  - `FROM` can appear multiple times within a single `Dockerfile` in order to create
   306  multiple images. Simply make a note of the last image ID output by the commit
   307  before each new `FROM` command.
   308  
   309  - The `tag` or `digest` values are optional. If you omit either of them, the builder
   310  assumes a `latest` by default. The builder returns an error if it cannot match
   311  the `tag` value.
   312  
   313  ## MAINTAINER
   314  
   315      MAINTAINER <name>
   316  
   317  The `MAINTAINER` instruction allows you to set the *Author* field of the
   318  generated images.
   319  
   320  ## RUN
   321  
   322  RUN has 2 forms:
   323  
   324  - `RUN <command>` (*shell* form, the command is run in a shell - `/bin/sh -c`)
   325  - `RUN ["executable", "param1", "param2"]` (*exec* form)
   326  
   327  The `RUN` instruction will execute any commands in a new layer on top of the
   328  current image and commit the results. The resulting committed image will be
   329  used for the next step in the `Dockerfile`.
   330  
   331  Layering `RUN` instructions and generating commits conforms to the core
   332  concepts of Docker where commits are cheap and containers can be created from
   333  any point in an image's history, much like source control.
   334  
   335  The *exec* form makes it possible to avoid shell string munging, and to `RUN`
   336  commands using a base image that does not contain `/bin/sh`.
   337  
   338  In the *shell* form you can use a `\` (backslash) to continue a single
   339  RUN instruction onto the next line. For example, consider these two lines:
   340  ```
   341  RUN /bin/bash -c 'source $HOME/.bashrc ;\
   342  echo $HOME'
   343  ```
   344  Together they are equivalent to this single line:
   345  ```
   346  RUN /bin/bash -c 'source $HOME/.bashrc ; echo $HOME'
   347  ```
   348  
   349  > **Note**:
   350  > To use a different shell, other than '/bin/sh', use the *exec* form
   351  > passing in the desired shell. For example,
   352  > `RUN ["/bin/bash", "-c", "echo hello"]`
   353  
   354  > **Note**:
   355  > The *exec* form is parsed as a JSON array, which means that
   356  > you must use double-quotes (") around words not single-quotes (').
   357  
   358  > **Note**:
   359  > Unlike the *shell* form, the *exec* form does not invoke a command shell.
   360  > This means that normal shell processing does not happen. For example,
   361  > `RUN [ "echo", "$HOME" ]` will not do variable substitution on `$HOME`.
   362  > If you want shell processing then either use the *shell* form or execute
   363  > a shell directly, for example: `RUN [ "sh", "-c", "echo", "$HOME" ]`.
   364  
   365  The cache for `RUN` instructions isn't invalidated automatically during
   366  the next build. The cache for an instruction like
   367  `RUN apt-get dist-upgrade -y` will be reused during the next build. The
   368  cache for `RUN` instructions can be invalidated by using the `--no-cache`
   369  flag, for example `docker build --no-cache`.
   370  
   371  See the [`Dockerfile` Best Practices
   372  guide](../articles/dockerfile_best-practices.md#build-cache) for more information.
   373  
   374  The cache for `RUN` instructions can be invalidated by `ADD` instructions. See
   375  [below](#add) for details.
   376  
   377  ### Known issues (RUN)
   378  
   379  - [Issue 783](https://github.com/docker/docker/issues/783) is about file
   380    permissions problems that can occur when using the AUFS file system. You
   381    might notice it during an attempt to `rm` a file, for example.
   382  
   383    For systems that have recent aufs version (i.e., `dirperm1` mount option can
   384    be set), docker will attempt to fix the issue automatically by mounting
   385    the layers with `dirperm1` option. More details on `dirperm1` option can be
   386    found at [`aufs` man page](http://aufs.sourceforge.net/aufs3/man.html)
   387  
   388    If your system doesn't have support for `dirperm1`, the issue describes a workaround.
   389  
   390  ## CMD
   391  
   392  The `CMD` instruction has three forms:
   393  
   394  - `CMD ["executable","param1","param2"]` (*exec* form, this is the preferred form)
   395  - `CMD ["param1","param2"]` (as *default parameters to ENTRYPOINT*)
   396  - `CMD command param1 param2` (*shell* form)
   397  
   398  There can only be one `CMD` instruction in a `Dockerfile`. If you list more than one `CMD`
   399  then only the last `CMD` will take effect.
   400  
   401  **The main purpose of a `CMD` is to provide defaults for an executing
   402  container.** These defaults can include an executable, or they can omit
   403  the executable, in which case you must specify an `ENTRYPOINT`
   404  instruction as well.
   405  
   406  > **Note**:
   407  > If `CMD` is used to provide default arguments for the `ENTRYPOINT`
   408  > instruction, both the `CMD` and `ENTRYPOINT` instructions should be specified
   409  > with the JSON array format.
   410  
   411  > **Note**:
   412  > The *exec* form is parsed as a JSON array, which means that
   413  > you must use double-quotes (") around words not single-quotes (').
   414  
   415  > **Note**:
   416  > Unlike the *shell* form, the *exec* form does not invoke a command shell.
   417  > This means that normal shell processing does not happen. For example,
   418  > `CMD [ "echo", "$HOME" ]` will not do variable substitution on `$HOME`.
   419  > If you want shell processing then either use the *shell* form or execute
   420  > a shell directly, for example: `CMD [ "sh", "-c", "echo", "$HOME" ]`.
   421  
   422  When used in the shell or exec formats, the `CMD` instruction sets the command
   423  to be executed when running the image.
   424  
   425  If you use the *shell* form of the `CMD`, then the `<command>` will execute in
   426  `/bin/sh -c`:
   427  
   428      FROM ubuntu
   429      CMD echo "This is a test." | wc -
   430  
   431  If you want to **run your** `<command>` **without a shell** then you must
   432  express the command as a JSON array and give the full path to the executable.
   433  **This array form is the preferred format of `CMD`.** Any additional parameters
   434  must be individually expressed as strings in the array:
   435  
   436      FROM ubuntu
   437      CMD ["/usr/bin/wc","--help"]
   438  
   439  If you would like your container to run the same executable every time, then
   440  you should consider using `ENTRYPOINT` in combination with `CMD`. See
   441  [*ENTRYPOINT*](#entrypoint).
   442  
   443  If the user specifies arguments to `docker run` then they will override the
   444  default specified in `CMD`.
   445  
   446  > **Note**:
   447  > don't confuse `RUN` with `CMD`. `RUN` actually runs a command and commits
   448  > the result; `CMD` does not execute anything at build time, but specifies
   449  > the intended command for the image.
   450  
   451  ## LABEL
   452  
   453      LABEL <key>=<value> <key>=<value> <key>=<value> ...
   454  
   455  The `LABEL` instruction adds metadata to an image. A `LABEL` is a
   456  key-value pair. To include spaces within a `LABEL` value, use quotes and
   457  backslashes as you would in command-line parsing. A few usage examples:
   458  
   459      LABEL "com.example.vendor"="ACME Incorporated"
   460      LABEL com.example.label-with-value="foo"
   461      LABEL version="1.0"
   462      LABEL description="This text illustrates \
   463      that label-values can span multiple lines."
   464  
   465  An image can have more than one label. To specify multiple labels,
   466  Docker recommends combining labels into a single `LABEL` instruction where
   467  possible. Each `LABEL` instruction produces a new layer which can result in an
   468  inefficient image if you use many labels. This example results in a single image
   469  layer.
   470  
   471      LABEL multi.label1="value1" multi.label2="value2" other="value3"
   472  
   473  The above can also be written as:
   474  
   475      LABEL multi.label1="value1" \
   476            multi.label2="value2" \
   477            other="value3"
   478  
   479  Labels are additive including `LABEL`s in `FROM` images. If Docker
   480  encounters a label/key that already exists, the new value overrides any previous
   481  labels with identical keys.
   482  
   483  To view an image's labels, use the `docker inspect` command.
   484  
   485      "Labels": {
   486          "com.example.vendor": "ACME Incorporated"
   487          "com.example.label-with-value": "foo",
   488          "version": "1.0",
   489          "description": "This text illustrates that label-values can span multiple lines.",
   490          "multi.label1": "value1",
   491          "multi.label2": "value2",
   492          "other": "value3"
   493      },
   494  
   495  ## EXPOSE
   496  
   497      EXPOSE <port> [<port>...]
   498  
   499  The `EXPOSE` instruction informs Docker that the container listens on the
   500  specified network ports at runtime. `EXPOSE` does not make the ports of the
   501  container accessible to the host. To do that, you must use either the `-p` flag
   502  to publish a range of ports or the `-P` flag to publish all of the exposed
   503  ports. You can expose one port number and publish it externally under another
   504  number.
   505  
   506  To set up port redirection on the host system, see [using the -P
   507  flag](run.md#expose-incoming-ports). The Docker network feature supports
   508  creating networks without the need to expose ports within the network, for
   509  detailed information see the  [overview of this
   510  feature](../userguide/networking/index.md)).
   511  
   512  ## ENV
   513  
   514      ENV <key> <value>
   515      ENV <key>=<value> ...
   516  
   517  The `ENV` instruction sets the environment variable `<key>` to the value
   518  `<value>`. This value will be in the environment of all "descendent"
   519  `Dockerfile` commands and can be [replaced inline](#environment-replacement) in
   520  many as well.
   521  
   522  The `ENV` instruction has two forms. The first form, `ENV <key> <value>`,
   523  will set a single variable to a value. The entire string after the first
   524  space will be treated as the `<value>` - including characters such as
   525  spaces and quotes.
   526  
   527  The second form, `ENV <key>=<value> ...`, allows for multiple variables to
   528  be set at one time. Notice that the second form uses the equals sign (=)
   529  in the syntax, while the first form does not. Like command line parsing,
   530  quotes and backslashes can be used to include spaces within values.
   531  
   532  For example:
   533  
   534      ENV myName="John Doe" myDog=Rex\ The\ Dog \
   535          myCat=fluffy
   536  
   537  and
   538  
   539      ENV myName John Doe
   540      ENV myDog Rex The Dog
   541      ENV myCat fluffy
   542  
   543  will yield the same net results in the final container, but the first form
   544  is preferred because it produces a single cache layer.
   545  
   546  The environment variables set using `ENV` will persist when a container is run
   547  from the resulting image. You can view the values using `docker inspect`, and
   548  change them using `docker run --env <key>=<value>`.
   549  
   550  > **Note**:
   551  > Environment persistence can cause unexpected side effects. For example,
   552  > setting `ENV DEBIAN_FRONTEND noninteractive` may confuse apt-get
   553  > users on a Debian-based image. To set a value for a single command, use
   554  > `RUN <key>=<value> <command>`.
   555  
   556  ## ADD
   557  
   558  ADD has two forms:
   559  
   560  - `ADD <src>... <dest>`
   561  - `ADD ["<src>",... "<dest>"]` (this form is required for paths containing
   562  whitespace)
   563  
   564  The `ADD` instruction copies new files, directories or remote file URLs from `<src>`
   565  and adds them to the filesystem of the container at the path `<dest>`.
   566  
   567  Multiple `<src>` resource may be specified but if they are files or
   568  directories then they must be relative to the source directory that is
   569  being built (the context of the build).
   570  
   571  Each `<src>` may contain wildcards and matching will be done using Go's
   572  [filepath.Match](http://golang.org/pkg/path/filepath#Match) rules. For example:
   573  
   574      ADD hom* /mydir/        # adds all files starting with "hom"
   575      ADD hom?.txt /mydir/    # ? is replaced with any single character, e.g., "home.txt"
   576  
   577  The `<dest>` is an absolute path, or a path relative to `WORKDIR`, into which
   578  the source will be copied inside the destination container.
   579  
   580      ADD test relativeDir/          # adds "test" to `WORKDIR`/relativeDir/
   581      ADD test /absoluteDir          # adds "test" to /absoluteDir
   582  
   583  All new files and directories are created with a UID and GID of 0.
   584  
   585  In the case where `<src>` is a remote file URL, the destination will
   586  have permissions of 600. If the remote file being retrieved has an HTTP
   587  `Last-Modified` header, the timestamp from that header will be used
   588  to set the `mtime` on the destination file. However, like any other file
   589  processed during an `ADD`, `mtime` will not be included in the determination
   590  of whether or not the file has changed and the cache should be updated.
   591  
   592  > **Note**:
   593  > If you build by passing a `Dockerfile` through STDIN (`docker
   594  > build - < somefile`), there is no build context, so the `Dockerfile`
   595  > can only contain a URL based `ADD` instruction. You can also pass a
   596  > compressed archive through STDIN: (`docker build - < archive.tar.gz`),
   597  > the `Dockerfile` at the root of the archive and the rest of the
   598  > archive will get used at the context of the build.
   599  
   600  > **Note**:
   601  > If your URL files are protected using authentication, you
   602  > will need to use `RUN wget`, `RUN curl` or use another tool from
   603  > within the container as the `ADD` instruction does not support
   604  > authentication.
   605  
   606  > **Note**:
   607  > The first encountered `ADD` instruction will invalidate the cache for all
   608  > following instructions from the Dockerfile if the contents of `<src>` have
   609  > changed. This includes invalidating the cache for `RUN` instructions.
   610  > See the [`Dockerfile` Best Practices
   611  guide](../articles/dockerfile_best-practices.md#build-cache) for more information.
   612  
   613  
   614  `ADD` obeys the following rules:
   615  
   616  - The `<src>` path must be inside the *context* of the build;
   617    you cannot `ADD ../something /something`, because the first step of a
   618    `docker build` is to send the context directory (and subdirectories) to the
   619    docker daemon.
   620  
   621  - If `<src>` is a URL and `<dest>` does not end with a trailing slash, then a
   622    file is downloaded from the URL and copied to `<dest>`.
   623  
   624  - If `<src>` is a URL and `<dest>` does end with a trailing slash, then the
   625    filename is inferred from the URL and the file is downloaded to
   626    `<dest>/<filename>`. For instance, `ADD http://example.com/foobar /` would
   627    create the file `/foobar`. The URL must have a nontrivial path so that an
   628    appropriate filename can be discovered in this case (`http://example.com`
   629    will not work).
   630  
   631  - If `<src>` is a directory, the entire contents of the directory are copied,
   632    including filesystem metadata.
   633  
   634  > **Note**:
   635  > The directory itself is not copied, just its contents.
   636  
   637  - If `<src>` is a *local* tar archive in a recognized compression format
   638    (identity, gzip, bzip2 or xz) then it is unpacked as a directory. Resources
   639    from *remote* URLs are **not** decompressed. When a directory is copied or
   640    unpacked, it has the same behavior as `tar -x`: the result is the union of:
   641  
   642      1. Whatever existed at the destination path and
   643      2. The contents of the source tree, with conflicts resolved in favor
   644         of "2." on a file-by-file basis.
   645  
   646  - If `<src>` is any other kind of file, it is copied individually along with
   647    its metadata. In this case, if `<dest>` ends with a trailing slash `/`, it
   648    will be considered a directory and the contents of `<src>` will be written
   649    at `<dest>/base(<src>)`.
   650  
   651  - If multiple `<src>` resources are specified, either directly or due to the
   652    use of a wildcard, then `<dest>` must be a directory, and it must end with
   653    a slash `/`.
   654  
   655  - If `<dest>` does not end with a trailing slash, it will be considered a
   656    regular file and the contents of `<src>` will be written at `<dest>`.
   657  
   658  - If `<dest>` doesn't exist, it is created along with all missing directories
   659    in its path.
   660  
   661  ## COPY
   662  
   663  COPY has two forms:
   664  
   665  - `COPY <src>... <dest>`
   666  - `COPY ["<src>",... "<dest>"]` (this form is required for paths containing
   667  whitespace)
   668  
   669  The `COPY` instruction copies new files or directories from `<src>`
   670  and adds them to the filesystem of the container at the path `<dest>`.
   671  
   672  Multiple `<src>` resource may be specified but they must be relative
   673  to the source directory that is being built (the context of the build).
   674  
   675  Each `<src>` may contain wildcards and matching will be done using Go's
   676  [filepath.Match](http://golang.org/pkg/path/filepath#Match) rules. For example:
   677  
   678      COPY hom* /mydir/        # adds all files starting with "hom"
   679      COPY hom?.txt /mydir/    # ? is replaced with any single character, e.g., "home.txt"
   680  
   681  The `<dest>` is an absolute path, or a path relative to `WORKDIR`, into which
   682  the source will be copied inside the destination container.
   683  
   684      COPY test relativeDir/   # adds "test" to `WORKDIR`/relativeDir/
   685      COPY test /absoluteDir   # adds "test" to /absoluteDir
   686  
   687  All new files and directories are created with a UID and GID of 0.
   688  
   689  > **Note**:
   690  > If you build using STDIN (`docker build - < somefile`), there is no
   691  > build context, so `COPY` can't be used.
   692  
   693  `COPY` obeys the following rules:
   694  
   695  - The `<src>` path must be inside the *context* of the build;
   696    you cannot `COPY ../something /something`, because the first step of a
   697    `docker build` is to send the context directory (and subdirectories) to the
   698    docker daemon.
   699  
   700  - If `<src>` is a directory, the entire contents of the directory are copied,
   701    including filesystem metadata.
   702  
   703  > **Note**:
   704  > The directory itself is not copied, just its contents.
   705  
   706  - If `<src>` is any other kind of file, it is copied individually along with
   707    its metadata. In this case, if `<dest>` ends with a trailing slash `/`, it
   708    will be considered a directory and the contents of `<src>` will be written
   709    at `<dest>/base(<src>)`.
   710  
   711  - If multiple `<src>` resources are specified, either directly or due to the
   712    use of a wildcard, then `<dest>` must be a directory, and it must end with
   713    a slash `/`.
   714  
   715  - If `<dest>` does not end with a trailing slash, it will be considered a
   716    regular file and the contents of `<src>` will be written at `<dest>`.
   717  
   718  - If `<dest>` doesn't exist, it is created along with all missing directories
   719    in its path.
   720  
   721  ## ENTRYPOINT
   722  
   723  ENTRYPOINT has two forms:
   724  
   725  - `ENTRYPOINT ["executable", "param1", "param2"]`
   726    (*exec* form, preferred)
   727  - `ENTRYPOINT command param1 param2`
   728    (*shell* form)
   729  
   730  An `ENTRYPOINT` allows you to configure a container that will run as an executable.
   731  
   732  For example, the following will start nginx with its default content, listening
   733  on port 80:
   734  
   735      docker run -i -t --rm -p 80:80 nginx
   736  
   737  Command line arguments to `docker run <image>` will be appended after all
   738  elements in an *exec* form `ENTRYPOINT`, and will override all elements specified
   739  using `CMD`.
   740  This allows arguments to be passed to the entry point, i.e., `docker run <image> -d`
   741  will pass the `-d` argument to the entry point.
   742  You can override the `ENTRYPOINT` instruction using the `docker run --entrypoint`
   743  flag.
   744  
   745  The *shell* form prevents any `CMD` or `run` command line arguments from being
   746  used, but has the disadvantage that your `ENTRYPOINT` will be started as a
   747  subcommand of `/bin/sh -c`, which does not pass signals.
   748  This means that the executable will not be the container's `PID 1` - and
   749  will _not_ receive Unix signals - so your executable will not receive a
   750  `SIGTERM` from `docker stop <container>`.
   751  
   752  Only the last `ENTRYPOINT` instruction in the `Dockerfile` will have an effect.
   753  
   754  ### Exec form ENTRYPOINT example
   755  
   756  You can use the *exec* form of `ENTRYPOINT` to set fairly stable default commands
   757  and arguments and then use either form of `CMD` to set additional defaults that
   758  are more likely to be changed.
   759  
   760      FROM ubuntu
   761      ENTRYPOINT ["top", "-b"]
   762      CMD ["-c"]
   763  
   764  When you run the container, you can see that `top` is the only process:
   765  
   766      $ docker run -it --rm --name test  top -H
   767      top - 08:25:00 up  7:27,  0 users,  load average: 0.00, 0.01, 0.05
   768      Threads:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
   769      %Cpu(s):  0.1 us,  0.1 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
   770      KiB Mem:   2056668 total,  1616832 used,   439836 free,    99352 buffers
   771      KiB Swap:  1441840 total,        0 used,  1441840 free.  1324440 cached Mem
   772  
   773        PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
   774          1 root      20   0   19744   2336   2080 R  0.0  0.1   0:00.04 top
   775  
   776  To examine the result further, you can use `docker exec`:
   777  
   778      $ docker exec -it test ps aux
   779      USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
   780      root         1  2.6  0.1  19752  2352 ?        Ss+  08:24   0:00 top -b -H
   781      root         7  0.0  0.1  15572  2164 ?        R+   08:25   0:00 ps aux
   782  
   783  And you can gracefully request `top` to shut down using `docker stop test`.
   784  
   785  The following `Dockerfile` shows using the `ENTRYPOINT` to run Apache in the
   786  foreground (i.e., as `PID 1`):
   787  
   788  ```
   789  FROM debian:stable
   790  RUN apt-get update && apt-get install -y --force-yes apache2
   791  EXPOSE 80 443
   792  VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2"]
   793  ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
   794  ```
   795  
   796  If you need to write a starter script for a single executable, you can ensure that
   797  the final executable receives the Unix signals by using `exec` and `gosu`
   798  commands:
   799  
   800  ```bash
   801  #!/bin/bash
   802  set -e
   803  
   804  if [ "$1" = 'postgres' ]; then
   805      chown -R postgres "$PGDATA"
   806  
   807      if [ -z "$(ls -A "$PGDATA")" ]; then
   808          gosu postgres initdb
   809      fi
   810  
   811      exec gosu postgres "$@"
   812  fi
   813  
   814  exec "$@"
   815  ```
   816  
   817  Lastly, if you need to do some extra cleanup (or communicate with other containers)
   818  on shutdown, or are co-ordinating more than one executable, you may need to ensure
   819  that the `ENTRYPOINT` script receives the Unix signals, passes them on, and then
   820  does some more work:
   821  
   822  ```
   823  #!/bin/sh
   824  # Note: I've written this using sh so it works in the busybox container too
   825  
   826  # USE the trap if you need to also do manual cleanup after the service is stopped,
   827  #     or need to start multiple services in the one container
   828  trap "echo TRAPed signal" HUP INT QUIT KILL TERM
   829  
   830  # start service in background here
   831  /usr/sbin/apachectl start
   832  
   833  echo "[hit enter key to exit] or run 'docker stop <container>'"
   834  read
   835  
   836  # stop service and clean up here
   837  echo "stopping apache"
   838  /usr/sbin/apachectl stop
   839  
   840  echo "exited $0"
   841  ```
   842  
   843  If you run this image with `docker run -it --rm -p 80:80 --name test apache`,
   844  you can then examine the container's processes with `docker exec`, or `docker top`,
   845  and then ask the script to stop Apache:
   846  
   847  ```bash
   848  $ docker exec -it test ps aux
   849  USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
   850  root         1  0.1  0.0   4448   692 ?        Ss+  00:42   0:00 /bin/sh /run.sh 123 cmd cmd2
   851  root        19  0.0  0.2  71304  4440 ?        Ss   00:42   0:00 /usr/sbin/apache2 -k start
   852  www-data    20  0.2  0.2 360468  6004 ?        Sl   00:42   0:00 /usr/sbin/apache2 -k start
   853  www-data    21  0.2  0.2 360468  6000 ?        Sl   00:42   0:00 /usr/sbin/apache2 -k start
   854  root        81  0.0  0.1  15572  2140 ?        R+   00:44   0:00 ps aux
   855  $ docker top test
   856  PID                 USER                COMMAND
   857  10035               root                {run.sh} /bin/sh /run.sh 123 cmd cmd2
   858  10054               root                /usr/sbin/apache2 -k start
   859  10055               33                  /usr/sbin/apache2 -k start
   860  10056               33                  /usr/sbin/apache2 -k start
   861  $ /usr/bin/time docker stop test
   862  test
   863  real	0m 0.27s
   864  user	0m 0.03s
   865  sys	0m 0.03s
   866  ```
   867  
   868  > **Note:** you can over ride the `ENTRYPOINT` setting using `--entrypoint`,
   869  > but this can only set the binary to *exec* (no `sh -c` will be used).
   870  
   871  > **Note**:
   872  > The *exec* form is parsed as a JSON array, which means that
   873  > you must use double-quotes (") around words not single-quotes (').
   874  
   875  > **Note**:
   876  > Unlike the *shell* form, the *exec* form does not invoke a command shell.
   877  > This means that normal shell processing does not happen. For example,
   878  > `ENTRYPOINT [ "echo", "$HOME" ]` will not do variable substitution on `$HOME`.
   879  > If you want shell processing then either use the *shell* form or execute
   880  > a shell directly, for example: `ENTRYPOINT [ "sh", "-c", "echo", "$HOME" ]`.
   881  > Variables that are defined in the `Dockerfile`using `ENV`, will be substituted by
   882  > the `Dockerfile` parser.
   883  
   884  ### Shell form ENTRYPOINT example
   885  
   886  You can specify a plain string for the `ENTRYPOINT` and it will execute in `/bin/sh -c`.
   887  This form will use shell processing to substitute shell environment variables,
   888  and will ignore any `CMD` or `docker run` command line arguments.
   889  To ensure that `docker stop` will signal any long running `ENTRYPOINT` executable
   890  correctly, you need to remember to start it with `exec`:
   891  
   892      FROM ubuntu
   893      ENTRYPOINT exec top -b
   894  
   895  When you run this image, you'll see the single `PID 1` process:
   896  
   897      $ docker run -it --rm --name test top
   898      Mem: 1704520K used, 352148K free, 0K shrd, 0K buff, 140368121167873K cached
   899      CPU:   5% usr   0% sys   0% nic  94% idle   0% io   0% irq   0% sirq
   900      Load average: 0.08 0.03 0.05 2/98 6
   901        PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
   902          1     0 root     R     3164   0%   0% top -b
   903  
   904  Which will exit cleanly on `docker stop`:
   905  
   906      $ /usr/bin/time docker stop test
   907      test
   908      real	0m 0.20s
   909      user	0m 0.02s
   910      sys	0m 0.04s
   911  
   912  If you forget to add `exec` to the beginning of your `ENTRYPOINT`:
   913  
   914      FROM ubuntu
   915      ENTRYPOINT top -b
   916      CMD --ignored-param1
   917  
   918  You can then run it (giving it a name for the next step):
   919  
   920      $ docker run -it --name test top --ignored-param2
   921      Mem: 1704184K used, 352484K free, 0K shrd, 0K buff, 140621524238337K cached
   922      CPU:   9% usr   2% sys   0% nic  88% idle   0% io   0% irq   0% sirq
   923      Load average: 0.01 0.02 0.05 2/101 7
   924        PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
   925          1     0 root     S     3168   0%   0% /bin/sh -c top -b cmd cmd2
   926          7     1 root     R     3164   0%   0% top -b
   927  
   928  You can see from the output of `top` that the specified `ENTRYPOINT` is not `PID 1`.
   929  
   930  If you then run `docker stop test`, the container will not exit cleanly - the
   931  `stop` command will be forced to send a `SIGKILL` after the timeout:
   932  
   933      $ docker exec -it test ps aux
   934      PID   USER     COMMAND
   935          1 root     /bin/sh -c top -b cmd cmd2
   936          7 root     top -b
   937          8 root     ps aux
   938      $ /usr/bin/time docker stop test
   939      test
   940      real	0m 10.19s
   941      user	0m 0.04s
   942      sys	0m 0.03s
   943  
   944  ## VOLUME
   945  
   946      VOLUME ["/data"]
   947  
   948  The `VOLUME` instruction creates a mount point with the specified name
   949  and marks it as holding externally mounted volumes from native host or other
   950  containers. The value can be a JSON array, `VOLUME ["/var/log/"]`, or a plain
   951  string with multiple arguments, such as `VOLUME /var/log` or `VOLUME /var/log
   952  /var/db`. For more information/examples and mounting instructions via the
   953  Docker client, refer to
   954  [*Share Directories via Volumes*](../userguide/dockervolumes.md#mount-a-host-directory-as-a-data-volume)
   955  documentation.
   956  
   957  The `docker run` command initializes the newly created volume with any data
   958  that exists at the specified location within the base image. For example,
   959  consider the following Dockerfile snippet:
   960  
   961      FROM ubuntu
   962      RUN mkdir /myvol
   963      RUN echo "hello world" > /myvol/greeting
   964      VOLUME /myvol
   965  
   966  This Dockerfile results in an image that causes `docker run`, to
   967  create a new mount point at `/myvol` and copy the  `greeting` file
   968  into the newly created volume.
   969  
   970  > **Note**:
   971  > If any build steps change the data within the volume after it has been
   972  > declared, those changes will be discarded.
   973  
   974  > **Note**:
   975  > The list is parsed as a JSON array, which means that
   976  > you must use double-quotes (") around words not single-quotes (').
   977  
   978  ## USER
   979  
   980      USER daemon
   981  
   982  The `USER` instruction sets the user name or UID to use when running the image
   983  and for any `RUN`, `CMD` and `ENTRYPOINT` instructions that follow it in the
   984  `Dockerfile`.
   985  
   986  ## WORKDIR
   987  
   988      WORKDIR /path/to/workdir
   989  
   990  The `WORKDIR` instruction sets the working directory for any `RUN`, `CMD`,
   991  `ENTRYPOINT`, `COPY` and `ADD` instructions that follow it in the `Dockerfile`.
   992  
   993  It can be used multiple times in the one `Dockerfile`. If a relative path
   994  is provided, it will be relative to the path of the previous `WORKDIR`
   995  instruction. For example:
   996  
   997      WORKDIR /a
   998      WORKDIR b
   999      WORKDIR c
  1000      RUN pwd
  1001  
  1002  The output of the final `pwd` command in this `Dockerfile` would be
  1003  `/a/b/c`.
  1004  
  1005  The `WORKDIR` instruction can resolve environment variables previously set using
  1006  `ENV`. You can only use environment variables explicitly set in the `Dockerfile`.
  1007  For example:
  1008  
  1009      ENV DIRPATH /path
  1010      WORKDIR $DIRPATH/$DIRNAME
  1011      RUN pwd
  1012  
  1013  The output of the final `pwd` command in this `Dockerfile` would be
  1014  `/path/$DIRNAME`
  1015  
  1016  ## ARG
  1017  
  1018      ARG <name>[=<default value>]
  1019  
  1020  The `ARG` instruction defines a variable that users can pass at build-time to
  1021  the builder with the `docker build` command using the `--build-arg
  1022  <varname>=<value>` flag. If a user specifies a build argument that was not
  1023  defined in the Dockerfile, the build outputs an error.
  1024  
  1025  ```
  1026  One or more build-args were not consumed, failing build.
  1027  ```
  1028  
  1029  The Dockerfile author can define a single variable by specifying `ARG` once or many
  1030  variables by specifying `ARG` more than once. For example, a valid Dockerfile:
  1031  
  1032  ```
  1033  FROM busybox
  1034  ARG user1
  1035  ARG buildno
  1036  ...
  1037  ```
  1038  
  1039  A Dockerfile author may optionally specify a default value for an `ARG` instruction:
  1040  
  1041  ```
  1042  FROM busybox
  1043  ARG user1=someuser
  1044  ARG buildno=1
  1045  ...
  1046  ```
  1047  
  1048  If an `ARG` value has a default and if there is no value passed at build-time, the
  1049  builder uses the default.
  1050  
  1051  An `ARG` variable definition comes into effect from the line on which it is
  1052  defined in the `Dockerfile` not from the argument's use on the command-line or
  1053  elsewhere.  For example, consider this Dockerfile:
  1054  
  1055  ```
  1056  1 FROM busybox
  1057  2 USER ${user:-some_user}
  1058  3 ARG user
  1059  4 USER $user
  1060  ...
  1061  ```
  1062  A user builds this file by calling:
  1063  
  1064  ```
  1065  $ docker build --build-arg user=what_user Dockerfile
  1066  ```
  1067  
  1068  The `USER` at line 2 evaluates to `some_user` as the `user` variable is defined on the
  1069  subsequent line 3. The `USER` at line 4 evaluates to `what_user` as `user` is
  1070  defined and the `what_user` value was passed on the command line. Prior to its definition by an
  1071  `ARG` instruction, any use of a variable results in an empty string.
  1072  
  1073  > **Note:** It is not recommended to use build-time variables for
  1074  >  passing secrets like github keys, user credentials etc.
  1075  
  1076  You can use an `ARG` or an `ENV` instruction to specify variables that are
  1077  available to the `RUN` instruction. Environment variables defined using the
  1078  `ENV` instruction always override an `ARG` instruction of the same name. Consider
  1079  this Dockerfile with an `ENV` and `ARG` instruction.
  1080  
  1081  ```
  1082  1 FROM ubuntu
  1083  2 ARG CONT_IMG_VER
  1084  3 ENV CONT_IMG_VER v1.0.0
  1085  4 RUN echo $CONT_IMG_VER
  1086  ```
  1087  Then, assume this image is built with this command:
  1088  
  1089  ```
  1090  $ docker build --build-arg CONT_IMG_VER=v2.0.1 Dockerfile
  1091  ```
  1092  
  1093  In this case, the `RUN` instruction uses `v1.0.0` instead of the `ARG` setting
  1094  passed by the user:`v2.0.1` This behavior is similar to a shell
  1095  script where a locally scoped variable overrides the variables passed as
  1096  arguments or inherited from environment, from its point of definition.
  1097  
  1098  Using the example above but a different `ENV` specification you can create more
  1099  useful interactions between `ARG` and `ENV` instructions:
  1100  
  1101  ```
  1102  1 FROM ubuntu
  1103  2 ARG CONT_IMG_VER
  1104  3 ENV CONT_IMG_VER ${CONT_IMG_VER:-v1.0.0}
  1105  4 RUN echo $CONT_IMG_VER
  1106  ```
  1107  
  1108  Unlike an `ARG` instruction, `ENV` values are always persisted in the built
  1109  image. Consider a docker build without the --build-arg flag:
  1110  
  1111  ```
  1112  $ docker build Dockerfile
  1113  ```
  1114  
  1115  Using this Dockerfile example, `CONT_IMG_VER` is still persisted in the image but
  1116  its value would be `v1.0.0` as it is the default set in line 3 by the `ENV` instruction.
  1117  
  1118  The variable expansion technique in this example allows you to pass arguments
  1119  from the command line and persist them in the final image by leveraging the
  1120  `ENV` instruction. Variable expansion is only supported for [a limited set of
  1121  Dockerfile instructions.](#environment-replacement)
  1122  
  1123  Docker has a set of predefined `ARG` variables that you can use without a
  1124  corresponding `ARG` instruction in the Dockerfile.
  1125  
  1126  * `HTTP_PROXY`
  1127  * `http_proxy`
  1128  * `HTTPS_PROXY`
  1129  * `https_proxy`
  1130  * `FTP_PROXY`
  1131  * `ftp_proxy`
  1132  * `NO_PROXY`
  1133  * `no_proxy`
  1134  
  1135  To use these, simply pass them on the command line using the `--build-arg
  1136  <varname>=<value>` flag.
  1137  
  1138  ### Impact on build caching
  1139  
  1140  `ARG` variables are not persisted into the built image as `ENV` variables are.
  1141  However, `ARG` variables do impact the build cache in similar ways. If a
  1142  Dockerfile defines an `ARG` variable whose value is different from a previous
  1143  build, then a "cache miss" occurs upon its first usage, not its declaration.
  1144  For example, consider this Dockerfile:
  1145  
  1146  ```
  1147  1 FROM ubuntu
  1148  2 ARG CONT_IMG_VER
  1149  3 RUN echo $CONT_IMG_VER
  1150  ```
  1151  
  1152  If you specify `--build-arg CONT_IMG_VER=<value>` on the command line the
  1153  specification on line 2 does not cause a cache miss; line 3 does cause a cache
  1154  miss. The definition on line 2 has no impact on the resulting image. The `RUN`
  1155  on line 3 executes a command and in doing so defines a set of environment
  1156  variables, including `CONT_IMG_VER`. At that point, the `ARG` variable may
  1157  impact the resulting image, so a cache miss occurs.
  1158  
  1159  Consider another example under the same command line:
  1160  
  1161  ```
  1162  1 FROM ubuntu
  1163  2 ARG CONT_IMG_VER
  1164  3 ENV CONT_IMG_VER $CONT_IMG_VER
  1165  4 RUN echo $CONT_IMG_VER
  1166  ```
  1167  In this example, the cache miss occurs on line 3. The miss happens because
  1168  the variable's value in the `ENV` references the `ARG` variable and that
  1169  variable is changed through the command line. In this example, the `ENV`
  1170  command causes the image to include the value.
  1171  
  1172  ## ONBUILD
  1173  
  1174      ONBUILD [INSTRUCTION]
  1175  
  1176  The `ONBUILD` instruction adds to the image a *trigger* instruction to
  1177  be executed at a later time, when the image is used as the base for
  1178  another build. The trigger will be executed in the context of the
  1179  downstream build, as if it had been inserted immediately after the
  1180  `FROM` instruction in the downstream `Dockerfile`.
  1181  
  1182  Any build instruction can be registered as a trigger.
  1183  
  1184  This is useful if you are building an image which will be used as a base
  1185  to build other images, for example an application build environment or a
  1186  daemon which may be customized with user-specific configuration.
  1187  
  1188  For example, if your image is a reusable Python application builder, it
  1189  will require application source code to be added in a particular
  1190  directory, and it might require a build script to be called *after*
  1191  that. You can't just call `ADD` and `RUN` now, because you don't yet
  1192  have access to the application source code, and it will be different for
  1193  each application build. You could simply provide application developers
  1194  with a boilerplate `Dockerfile` to copy-paste into their application, but
  1195  that is inefficient, error-prone and difficult to update because it
  1196  mixes with application-specific code.
  1197  
  1198  The solution is to use `ONBUILD` to register advance instructions to
  1199  run later, during the next build stage.
  1200  
  1201  Here's how it works:
  1202  
  1203  1. When it encounters an `ONBUILD` instruction, the builder adds a
  1204     trigger to the metadata of the image being built. The instruction
  1205     does not otherwise affect the current build.
  1206  2. At the end of the build, a list of all triggers is stored in the
  1207     image manifest, under the key `OnBuild`. They can be inspected with
  1208     the `docker inspect` command.
  1209  3. Later the image may be used as a base for a new build, using the
  1210     `FROM` instruction. As part of processing the `FROM` instruction,
  1211     the downstream builder looks for `ONBUILD` triggers, and executes
  1212     them in the same order they were registered. If any of the triggers
  1213     fail, the `FROM` instruction is aborted which in turn causes the
  1214     build to fail. If all triggers succeed, the `FROM` instruction
  1215     completes and the build continues as usual.
  1216  4. Triggers are cleared from the final image after being executed. In
  1217     other words they are not inherited by "grand-children" builds.
  1218  
  1219  For example you might add something like this:
  1220  
  1221      [...]
  1222      ONBUILD ADD . /app/src
  1223      ONBUILD RUN /usr/local/bin/python-build --dir /app/src
  1224      [...]
  1225  
  1226  > **Warning**: Chaining `ONBUILD` instructions using `ONBUILD ONBUILD` isn't allowed.
  1227  
  1228  > **Warning**: The `ONBUILD` instruction may not trigger `FROM` or `MAINTAINER` instructions.
  1229  
  1230  ## STOPSIGNAL
  1231  
  1232  	STOPSIGNAL signal
  1233  
  1234  The `STOPSIGNAL` instruction sets the system call signal that will be sent to the container to exit.
  1235  This signal can be a valid unsigned number that matches a position in the kernel's syscall table, for instance 9,
  1236  or a signal name in the format SIGNAME, for instance SIGKILL.
  1237  
  1238  ## Dockerfile examples
  1239  
  1240  Below you can see some examples of Dockerfile syntax. If you're interested in
  1241  something more realistic, take a look at the list of [Dockerization examples](../examples/index.md).
  1242  
  1243  ```
  1244  # Nginx
  1245  #
  1246  # VERSION               0.0.1
  1247  
  1248  FROM      ubuntu
  1249  MAINTAINER Victor Vieux <victor@docker.com>
  1250  
  1251  LABEL Description="This image is used to start the foobar executable" Vendor="ACME Products" Version="1.0"
  1252  RUN apt-get update && apt-get install -y inotify-tools nginx apache2 openssh-server
  1253  ```
  1254  
  1255  ```
  1256  # Firefox over VNC
  1257  #
  1258  # VERSION               0.3
  1259  
  1260  FROM ubuntu
  1261  
  1262  # Install vnc, xvfb in order to create a 'fake' display and firefox
  1263  RUN apt-get update && apt-get install -y x11vnc xvfb firefox
  1264  RUN mkdir ~/.vnc
  1265  # Setup a password
  1266  RUN x11vnc -storepasswd 1234 ~/.vnc/passwd
  1267  # Autostart firefox (might not be the best way, but it does the trick)
  1268  RUN bash -c 'echo "firefox" >> /.bashrc'
  1269  
  1270  EXPOSE 5900
  1271  CMD    ["x11vnc", "-forever", "-usepw", "-create"]
  1272  ```
  1273  
  1274  ```
  1275  # Multiple images example
  1276  #
  1277  # VERSION               0.1
  1278  
  1279  FROM ubuntu
  1280  RUN echo foo > bar
  1281  # Will output something like ===> 907ad6c2736f
  1282  
  1283  FROM ubuntu
  1284  RUN echo moo > oink
  1285  # Will output something like ===> 695d7793cbe4
  1286  
  1287  # You᾿ll now have two images, 907ad6c2736f with /bar, and 695d7793cbe4 with
  1288  # /oink.
  1289  ```