38a67a
% "CONTAINERFILE" "5" "Aug 2021" "" "Container User Manuals"
38a67a
38a67a
# NAME
38a67a
38a67a
Containerfile(Dockerfile) - automate the steps of creating a container image
38a67a
38a67a
# INTRODUCTION
38a67a
38a67a
The **Containerfile** is a configuration file that automates the steps of creating a container image. It is similar to a Makefile. Container engines (Podman, Buildah, Docker) read instructions from the **Containerfile** to automate the steps otherwise performed manually to create an image. To build an image, create a file called **Containerfile**.
38a67a
38a67a
The **Containerfile** describes the steps taken to assemble the image. When the
38a67a
**Containerfile** has been created, call the `buildah bud`, `podman build`, `docker build` command,
38a67a
using the path of context directory that contains **Containerfile** as the argument. Podman and Buildah default to **Containerfile** and will fall back to **Dockerfile**. Docker only will search for **Dockerfile** in the context directory.
38a67a
38a67a
38a67a
**Dockerfile** is an alternate name for the same object.  **Containerfile** and **Dockerfile** support the same syntax.
38a67a
38a67a
# SYNOPSIS
38a67a
38a67a
INSTRUCTION arguments
38a67a
38a67a
For example:
38a67a
38a67a
  FROM image
38a67a
38a67a
# DESCRIPTION
38a67a
38a67a
A Containerfile is a file that automates the steps of creating a container image.
38a67a
A Containerfile is similar to a Makefile.
38a67a
38a67a
# USAGE
38a67a
38a67a
  ```
38a67a
  buildah bud .
38a67a
  podman build .
38a67a
  ```
38a67a
38a67a
  -- Runs the steps and commits them, building a final image.
38a67a
  The path to the source repository defines where to find the context of the
38a67a
  build.
38a67a
38a67a
  ```
38a67a
  buildah bud -t repository/tag .
38a67a
  podman build -t repository/tag .
38a67a
  ```
38a67a
38a67a
  -- specifies a repository and tag at which to save the new image if the build
38a67a
  succeeds. The container engine runs the steps one-by-one, committing the result
38a67a
  to a new image if necessary, before finally outputting the ID of the new
38a67a
  image.
38a67a
38a67a
  Container engines re-use intermediate images whenever possible. This significantly
38a67a
  accelerates the *build* process.
38a67a
38a67a
# FORMAT
38a67a
38a67a
  `FROM image`
38a67a
38a67a
  `FROM image:tag`
38a67a
38a67a
  `FROM image@digest`
38a67a
38a67a
  -- The **FROM** instruction sets the base image for subsequent instructions. A
38a67a
  valid Containerfile must have either **ARG** or *FROM** as its first instruction.
38a67a
  If **FROM** is not the first instruction in the file, it may only be preceded by
38a67a
  one or more ARG instructions, which declare arguments that are used in the next FROM line in the Containerfile.
38a67a
  The image can be any valid image. It is easy to start by pulling an image from the public
38a67a
  repositories.
38a67a
38a67a
  -- **FROM** must appear at least once in the Containerfile.
38a67a
38a67a
  -- **FROM** The first **FROM** command must come before all other instructions in
38a67a
  the Containerfile except **ARG**
38a67a
38a67a
  -- **FROM** may appear multiple times within a single Containerfile in order to create
38a67a
  multiple images. Make a note of the last image ID output by the commit before
38a67a
  each new **FROM** command.
38a67a
38a67a
  -- If no tag is given to the **FROM** instruction, container engines apply the
38a67a
  `latest` tag. If the used tag does not exist, an error is returned.
38a67a
38a67a
  -- If no digest is given to the **FROM** instruction, container engines apply the
38a67a
  `latest` tag. If the used tag does not exist, an error is returned.
38a67a
38a67a
**MAINTAINER**
38a67a
  -- **MAINTAINER** sets the Author field for the generated images.
38a67a
  Useful for providing users with an email or url for support.
38a67a
38a67a
**RUN**
38a67a
  -- **RUN** has two forms:
38a67a
38a67a
  ```
38a67a
  # the command is run in a shell - /bin/sh -c
38a67a
  RUN <command>
38a67a
38a67a
  # Executable form
38a67a
  RUN ["executable", "param1", "param2"]
38a67a
  ```
38a67a
**RUN mounts**
38a67a
38a67a
**--mount**=*type=TYPE,TYPE-SPECIFIC-OPTION[,...]*
38a67a
38a67a
Attach a filesystem mount to the container
38a67a
38a67a
Current supported mount TYPES are bind, cache, secret and tmpfs.
38a67a
38a67a
       e.g.
38a67a
38a67a
       mount=type=bind,source=/path/on/host,destination=/path/in/container
38a67a
38a67a
       mount=type=tmpfs,tmpfs-size=512M,destination=/path/in/container
38a67a
38a67a
       mount=type=secret,id=mysecret cat /run/secrets/mysecret
38a67a
38a67a
       Common Options:
38a67a
38a67a
              · src, source: mount source spec for bind and volume. Mandatory for bind. If `from` is specified, `src` is the subpath in the `from` field.
38a67a
38a67a
              · dst, destination, target: mount destination spec.
38a67a
0a8224
              · ro, read-only: true (default) or false.
38a67a
38a67a
       Options specific to bind:
38a67a
38a67a
              · bind-propagation: shared, slave, private, rshared, rslave, or rprivate(default). See also mount(2).
38a67a
38a67a
              . bind-nonrecursive: do not setup a recursive bind mount.  By default it is recursive.
38a67a
38a67a
              · from: stage or image name for the root of the source. Defaults to the build context.
38a67a
0a8224
              · rw, read-write: allows writes on the mount.
0a8224
38a67a
       Options specific to tmpfs:
38a67a
38a67a
              · tmpfs-size: Size of the tmpfs mount in bytes. Unlimited by default in Linux.
38a67a
38a67a
              · tmpfs-mode: File mode of the tmpfs in octal. (e.g. 700 or 0700.) Defaults to 1777 in Linux.
38a67a
38a67a
              · tmpcopyup: Path that is shadowed by the tmpfs mount is recursively copied up to the tmpfs itself.
38a67a
38a67a
	Options specific to cache:
38a67a
38a67a
              · id: Create a separate cache directory for a particular id.
38a67a
38a67a
              · mode: File mode for new cache directory in octal. Default 0755.
38a67a
38a67a
              · ro, readonly: read only cache if set.
38a67a
38a67a
              · uid: uid for cache directory.
38a67a
38a67a
              · gid: gid for cache directory.
38a67a
38a67a
              · from: stage name for the root of the source. Defaults to host cache directory.
38a67a
0a8224
              · rw, read-write: allows writes on the mount.
0a8224
38a67a
38a67a
**RUN Secrets**
38a67a
38a67a
The RUN command has a feature to allow the passing of secret information into the image build. These secrets files can be used during the RUN command but are not committed to the final image. The `RUN` command supports the `--mount` option to identify the secret file. A secret file from the host is mounted into the container while the image is being built.
38a67a
38a67a
Container engines pass secret the secret file into the build using the `--secret` flag.
38a67a
38a67a
**--mount**=*type=secret,TYPE-SPECIFIC-OPTION[,...]*
38a67a
38a67a
- `id` is the identifier for the secret passed into the `buildah bud --secret` or `podman build --secret`. This identifier is associated with the RUN --mount identifier to use in the Containerfile.
38a67a
38a67a
- `dst`|`target`|`destination` rename the secret file to a specific file in the Containerfile RUN command to use.
38a67a
38a67a
- `type=secret` tells the --mount command that it is mounting in a secret file
38a67a
38a67a
```
38a67a
# shows secret from default secret location:
38a67a
RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret
38a67a
```
38a67a
```
38a67a
# shows secret from custom secret location:
38a67a
RUN --mount=type=secret,id=mysecret,dst=/foobar cat /foobar
38a67a
```
38a67a
The secret needs to be passed to the build using the --secret flag. The final image built does not container the secret file:
38a67a
38a67a
```
38a67a
 buildah bud --no-cache --secret id=mysecret,src=mysecret.txt .
38a67a
```
38a67a
38a67a
  -- The **RUN** instruction executes any commands in a new layer on top of the current
38a67a
  image and commits the results. The committed image is used for the next step in
38a67a
  Containerfile.
38a67a
38a67a
  -- Layering **RUN** instructions and generating commits conforms to the core
38a67a
  concepts of container engines where commits are cheap and containers can be created from
38a67a
  any point in the history of an image. This is similar to source control.  The
38a67a
  exec form makes it possible to avoid shell string munging. The exec form makes
38a67a
  it possible to **RUN** commands using a base image that does not contain `/bin/sh`.
38a67a
38a67a
  Note that the exec form is parsed as a JSON array, which means that you must
38a67a
  use double-quotes (") around words, not single-quotes (').
38a67a
38a67a
**CMD**
38a67a
  -- **CMD** has three forms:
38a67a
38a67a
  ```
38a67a
  # Executable form
38a67a
  CMD ["executable", "param1", "param2"]`
38a67a
38a67a
  # Provide default arguments to ENTRYPOINT
38a67a
  CMD ["param1", "param2"]`
38a67a
38a67a
  # the command is run in a shell - /bin/sh -c
38a67a
  CMD command param1 param2
38a67a
  ```
38a67a
38a67a
  -- There should be only one **CMD** in a Containerfile. If more than one **CMD** is listed, only
38a67a
  the last **CMD** takes effect.
38a67a
  The main purpose of a **CMD** is to provide defaults for an executing container.
38a67a
  These defaults may include an executable, or they can omit the executable. If
38a67a
  they omit the executable, an **ENTRYPOINT** must be specified.
38a67a
  When used in the shell or exec formats, the **CMD** instruction sets the command to
38a67a
  be executed when running the image.
38a67a
  If you use the shell form of the **CMD**, the `<command>` executes in `/bin/sh -c`:
38a67a
38a67a
  Note that the exec form is parsed as a JSON array, which means that you must
38a67a
  use double-quotes (") around words, not single-quotes (').
38a67a
38a67a
  ```
38a67a
  FROM ubuntu
38a67a
  CMD echo "This is a test." | wc -
38a67a
  ```
38a67a
38a67a
  -- If you run **command** without a shell, then you must express the command as a
38a67a
  JSON array and give the full path to the executable. This array form is the
38a67a
  preferred form of **CMD**. All additional parameters must be individually expressed
38a67a
  as strings in the array:
38a67a
38a67a
  ```
38a67a
  FROM ubuntu
38a67a
  CMD ["/usr/bin/wc","--help"]
38a67a
  ```
38a67a
38a67a
  -- To make the container run the same executable every time, use **ENTRYPOINT** in
38a67a
  combination with **CMD**.
38a67a
  If the user specifies arguments to `podman run` or `docker run`, the specified commands
38a67a
  override the default in **CMD**.
38a67a
  Do not confuse **RUN** with **CMD**. **RUN** runs a command and commits the result.
38a67a
  **CMD** executes nothing at build time, but specifies the intended command for
38a67a
  the image.
38a67a
38a67a
**LABEL**
38a67a
  -- `LABEL <key>=<value> [<key>=<value> ...]`or
38a67a
  ```
38a67a
  LABEL <key>[ <value>]
38a67a
  LABEL <key>[ <value>]
38a67a
  ...
38a67a
  ```
38a67a
  The **LABEL** instruction adds metadata to an image. A **LABEL** is a
38a67a
  key-value pair. To specify a **LABEL** without a value, simply use an empty
38a67a
  string. To include spaces within a **LABEL** value, use quotes and
38a67a
  backslashes as you would in command-line parsing.
38a67a
38a67a
  ```
38a67a
  LABEL com.example.vendor="ACME Incorporated"
38a67a
  LABEL com.example.vendor "ACME Incorporated"
38a67a
  LABEL com.example.vendor.is-beta ""
38a67a
  LABEL com.example.vendor.is-beta=
38a67a
  LABEL com.example.vendor.is-beta=""
38a67a
  ```
38a67a
38a67a
  An image can have more than one label. To specify multiple labels, separate
38a67a
  each key-value pair by a space.
38a67a
38a67a
  Labels are additive including `LABEL`s in `FROM` images. As the system
38a67a
  encounters and then applies a new label, new `key`s override any previous
38a67a
  labels with identical keys.
38a67a
38a67a
  To display an image's labels, use the `buildah inspect` command.
38a67a
38a67a
**EXPOSE**
38a67a
  -- `EXPOSE <port> [<port>...]`
38a67a
  The **EXPOSE** instruction informs the container engine that the container listens on the
38a67a
  specified network ports at runtime. The container engine uses this information to
38a67a
  interconnect containers using links and to set up port redirection on the host
38a67a
  system.
38a67a
38a67a
**ENV**
38a67a
  -- `ENV <key> <value>`
38a67a
  The **ENV** instruction sets the environment variable <key> to
38a67a
  the value `<value>`. This value is passed to all future
38a67a
  **RUN**, **ENTRYPOINT**, and **CMD** instructions. This is
38a67a
  functionally equivalent to prefixing the command with `<key>=<value>`.  The
38a67a
  environment variables that are set with **ENV** persist when a container is run
38a67a
  from the resulting image. Use `podman inspect` to inspect these values, and
38a67a
  change them using `podman run --env <key>=<value>`.
38a67a
38a67a
  Note that setting "`ENV DEBIAN_FRONTEND=noninteractive`" may cause
38a67a
  unintended consequences, because it will persist when the container is run
38a67a
  interactively, as with the following command: `podman run -t -i image bash`
38a67a
38a67a
**ADD**
38a67a
  -- **ADD** has two forms:
38a67a
38a67a
  ```
38a67a
  ADD <src> <dest>
38a67a
38a67a
  # Required for paths with whitespace
38a67a
  ADD ["<src>",... "<dest>"]
38a67a
  ```
38a67a
38a67a
  The **ADD** instruction copies new files, directories
38a67a
  or remote file URLs to the filesystem of the container at path `<dest>`.
38a67a
  Multiple `<src>` resources may be specified but if they are files or directories
38a67a
  then they must be relative to the source directory that is being built
38a67a
  (the context of the build). The `<dest>` is the absolute path, or path relative
38a67a
  to **WORKDIR**, into which the source is copied inside the target container.
38a67a
  If the `<src>` argument is a local file in a recognized compression format
38a67a
  (tar, gzip, bzip2, etc) then it is unpacked at the specified `<dest>` in the
38a67a
  container's filesystem.  Note that only local compressed files will be unpacked,
38a67a
  i.e., the URL download and archive unpacking features cannot be used together.
38a67a
  All new directories are created with mode 0755 and with the uid and gid of **0**.
38a67a
38a67a
**COPY**
38a67a
  -- **COPY** has two forms:
38a67a
38a67a
  ```
38a67a
  COPY <src> <dest>
38a67a
38a67a
  # Required for paths with whitespace
38a67a
  COPY ["<src>",... "<dest>"]
38a67a
  ```
38a67a
38a67a
  The **COPY** instruction copies new files from `<src>` and
38a67a
  adds them to the filesystem of the container at path <dest>. The `<src>` must be
38a67a
  the path to a file or directory relative to the source directory that is
38a67a
  being built (the context of the build) or a remote file URL. The `<dest>` is an
38a67a
  absolute path, or a path relative to **WORKDIR**, into which the source will
38a67a
  be copied inside the target container. If you **COPY** an archive file it will
38a67a
  land in the container exactly as it appears in the build context without any
38a67a
  attempt to unpack it.  All new files and directories are created with mode **0755**
38a67a
  and with the uid and gid of **0**.
38a67a
38a67a
**ENTRYPOINT**
38a67a
  -- **ENTRYPOINT** has two forms:
38a67a
38a67a
  ```
38a67a
  # executable form
38a67a
  ENTRYPOINT ["executable", "param1", "param2"]`
38a67a
38a67a
  # run command in a shell - /bin/sh -c
38a67a
  ENTRYPOINT command param1 param2
38a67a
  ```
38a67a
38a67a
  -- An **ENTRYPOINT** helps you configure a
38a67a
  container that can be run as an executable. When you specify an **ENTRYPOINT**,
38a67a
  the whole container runs as if it was only that executable.  The **ENTRYPOINT**
38a67a
  instruction adds an entry command that is not overwritten when arguments are
38a67a
  passed to `podman run`. This is different from the behavior of **CMD**. This allows
38a67a
  arguments to be passed to the entrypoint, for instance `podman run <image> -d`
38a67a
  passes the -d argument to the **ENTRYPOINT**.  Specify parameters either in the
38a67a
  **ENTRYPOINT** JSON array (as in the preferred exec form above), or by using a **CMD**
38a67a
  statement.  Parameters in the **ENTRYPOINT** are not overwritten by the `podman run` arguments.  Parameters specified via **CMD** are overwritten by `podman run` arguments.  Specify a plain string for the **ENTRYPOINT**, and it will execute in
38a67a
  `/bin/sh -c`, like a **CMD** instruction:
38a67a
38a67a
  ```
38a67a
  FROM ubuntu
38a67a
  ENTRYPOINT wc -l -
38a67a
  ```
38a67a
38a67a
  This means that the Containerfile's image always takes stdin as input (that's
38a67a
  what "-" means), and prints the number of lines (that's what "-l" means). To
38a67a
  make this optional but default, use a **CMD**:
38a67a
38a67a
  ```
38a67a
  FROM ubuntu
38a67a
  CMD ["-l", "-"]
38a67a
  ENTRYPOINT ["/usr/bin/wc"]
38a67a
  ```
38a67a
38a67a
**VOLUME**
38a67a
  -- `VOLUME ["/data"]`
38a67a
  The **VOLUME** instruction creates a mount point with the specified name and marks
38a67a
  it as holding externally-mounted volumes from the native host or from other
38a67a
  containers.
38a67a
38a67a
**USER**
38a67a
  -- `USER daemon`
38a67a
  Sets the username or UID used for running subsequent commands.
38a67a
38a67a
  The **USER** instruction can optionally be used to set the group or GID. The
38a67a
  following examples are all valid:
38a67a
  USER [user | user:group | uid | uid:gid | user:gid | uid:group ]
38a67a
38a67a
  Until the **USER** instruction is set, instructions will be run as root. The USER
38a67a
  instruction can be used any number of times in a Containerfile, and will only affect
38a67a
  subsequent commands.
38a67a
38a67a
**WORKDIR**
38a67a
  -- `WORKDIR /path/to/workdir`
38a67a
  The **WORKDIR** instruction sets the working directory for the **RUN**, **CMD**,
38a67a
  **ENTRYPOINT**, **COPY** and **ADD** Containerfile commands that follow it. It can
38a67a
  be used multiple times in a single Containerfile. Relative paths are defined
38a67a
  relative to the path of the previous **WORKDIR** instruction. For example:
38a67a
38a67a
  ```
38a67a
  WORKDIR /a
38a67a
  WORKDIR b
38a67a
  WORKDIR c
38a67a
  RUN pwd
38a67a
  ```
38a67a
38a67a
  In the above example, the output of the **pwd** command is **a/b/c**.
38a67a
38a67a
**ARG**
38a67a
   -- ARG <name>[=<default value>]
38a67a
38a67a
  The `ARG` instruction defines a variable that users can pass at build-time to
38a67a
  the builder with the `podman build` and `buildah build` commands using the
38a67a
  `--build-arg <varname>=<value>` flag. If a user specifies a build argument that
38a67a
  was not defined in the Containerfile, the build outputs a warning.
38a67a
38a67a
  Note that a second FROM in a Containerfile sets the values associated with an
38a67a
  Arg variable to nil and they must be reset if they are to be used later in
38a67a
  the Containerfile
38a67a
38a67a
```
38a67a
  [Warning] One or more build-args [foo] were not consumed
38a67a
  ```
38a67a
38a67a
  The Containerfile author can define a single variable by specifying `ARG` once or many
38a67a
  variables by specifying `ARG` more than once. For example, a valid Containerfile:
38a67a
38a67a
  ```
38a67a
  FROM busybox
38a67a
  ARG user1
38a67a
  ARG buildno
38a67a
  ...
38a67a
  ```
38a67a
38a67a
  A Containerfile author may optionally specify a default value for an `ARG` instruction:
38a67a
38a67a
  ```
38a67a
  FROM busybox
38a67a
  ARG user1=someuser
38a67a
  ARG buildno=1
38a67a
  ...
38a67a
  ```
38a67a
38a67a
  If an `ARG` value has a default and if there is no value passed at build-time, the
38a67a
  builder uses the default.
38a67a
38a67a
  An `ARG` variable definition comes into effect from the line on which it is
38a67a
  defined in the `Containerfile` not from the argument's use on the command-line or
38a67a
  elsewhere.  For example, consider this Containerfile:
38a67a
38a67a
  ```
38a67a
  1 FROM busybox
38a67a
  2 USER ${user:-some_user}
38a67a
  3 ARG user
38a67a
  4 USER $user
38a67a
  ...
38a67a
  ```
38a67a
  A user builds this file by calling:
38a67a
38a67a
  ```
38a67a
  $ podman build --build-arg user=what_user Containerfile
38a67a
  ```
38a67a
38a67a
  The `USER` at line 2 evaluates to `some_user` as the `user` variable is defined on the
38a67a
  subsequent line 3. The `USER` at line 4 evaluates to `what_user` as `user` is
38a67a
  defined and the `what_user` value was passed on the command line. Prior to its definition by an
38a67a
  `ARG` instruction, any use of a variable results in an empty string.
38a67a
38a67a
  > **Warning:** It is not recommended to use build-time variables for
38a67a
  >  passing secrets like github keys, user credentials etc. Build-time variable
38a67a
  >  values are visible to any user of the image with the `podman history` command.
38a67a
38a67a
  You can use an `ARG` or an `ENV` instruction to specify variables that are
38a67a
  available to the `RUN` instruction. Environment variables defined using the
38a67a
  `ENV` instruction always override an `ARG` instruction of the same name. Consider
38a67a
  this Containerfile with an `ENV` and `ARG` instruction.
38a67a
38a67a
  ```
38a67a
  1 FROM ubuntu
38a67a
  2 ARG CONT_IMG_VER
38a67a
  3 ENV CONT_IMG_VER=v1.0.0
38a67a
  4 RUN echo $CONT_IMG_VER
38a67a
  ```
38a67a
  Then, assume this image is built with this command:
38a67a
38a67a
  ```
38a67a
  $ podman build --build-arg CONT_IMG_VER=v2.0.1 Containerfile
38a67a
  ```
38a67a
38a67a
  In this case, the `RUN` instruction uses `v1.0.0` instead of the `ARG` setting
38a67a
  passed by the user:`v2.0.1` This behavior is similar to a shell
38a67a
  script where a locally scoped variable overrides the variables passed as
38a67a
  arguments or inherited from environment, from its point of definition.
38a67a
38a67a
  Using the example above but a different `ENV` specification you can create more
38a67a
  useful interactions between `ARG` and `ENV` instructions:
38a67a
38a67a
  ```
38a67a
  1 FROM ubuntu
38a67a
  2 ARG CONT_IMG_VER
38a67a
  3 ENV CONT_IMG_VER=${CONT_IMG_VER:-v1.0.0}
38a67a
  4 RUN echo $CONT_IMG_VER
38a67a
  ```
38a67a
38a67a
  Unlike an `ARG` instruction, `ENV` values are always persisted in the built
38a67a
  image. Consider a `podman build` without the --build-arg flag:
38a67a
38a67a
  ```
38a67a
  $ podman build Containerfile
38a67a
  ```
38a67a
38a67a
  Using this Containerfile example, `CONT_IMG_VER` is still persisted in the image but
38a67a
  its value would be `v1.0.0` as it is the default set in line 3 by the `ENV` instruction.
38a67a
38a67a
  The variable expansion technique in this example allows you to pass arguments
38a67a
  from the command line and persist them in the final image by leveraging the
38a67a
  `ENV` instruction. Variable expansion is only supported for [a limited set of
38a67a
  Containerfile instructions.](#environment-replacement)
38a67a
38a67a
  Container engines have a set of predefined `ARG` variables that you can use without a
38a67a
  corresponding `ARG` instruction in the Containerfile.
38a67a
38a67a
  * `HTTP_PROXY`
38a67a
  * `http_proxy`
38a67a
  * `HTTPS_PROXY`
38a67a
  * `https_proxy`
38a67a
  * `FTP_PROXY`
38a67a
  * `ftp_proxy`
38a67a
  * `NO_PROXY`
38a67a
  * `no_proxy`
38a67a
  * `ALL_PROXY`
38a67a
  * `all_proxy`
38a67a
38a67a
  To use these, pass them on the command line using `--build-arg` flag, for
38a67a
  example:
38a67a
38a67a
  ```
38a67a
  $ podman build --build-arg HTTPS_PROXY=https://my-proxy.example.com .
38a67a
  ```
38a67a
38a67a
**ONBUILD**
38a67a
  -- `ONBUILD [INSTRUCTION]`
38a67a
  The **ONBUILD** instruction adds a trigger instruction to an image. The
38a67a
  trigger is executed at a later time, when the image is used as the base for
38a67a
  another build. Container engines execute the trigger in the context of the downstream
38a67a
  build, as if the trigger existed immediately after the **FROM** instruction in
38a67a
  the downstream Containerfile.
38a67a
38a67a
  You can register any build instruction as a trigger. A trigger is useful if
38a67a
  you are defining an image to use as a base for building other images. For
38a67a
  example, if you are defining an application build environment or a daemon that
38a67a
  is customized with a user-specific configuration.
38a67a
38a67a
  Consider an image intended as a reusable python application builder. It must
38a67a
  add application source code to a particular directory, and might need a build
38a67a
  script called after that. You can't just call **ADD** and **RUN** now, because
38a67a
  you don't yet have access to the application source code, and it is different
38a67a
  for each application build.
38a67a
38a67a
  -- Providing application developers with a boilerplate Containerfile to copy-paste
38a67a
  into their application is inefficient, error-prone, and
38a67a
  difficult to update because it mixes with application-specific code.
38a67a
  The solution is to use **ONBUILD** to register instructions in advance, to
38a67a
  run later, during the next build stage.
38a67a
38a67a
## SEE ALSO
38a67a
buildah(1), podman(1), docker(1)
38a67a
38a67a
# HISTORY
38a67a
```
38a67a
May 2014, Compiled by Zac Dover (zdover at redhat dot com) based on docker.com Dockerfile documentation.
38a67a
Feb 2015, updated by Brian Goff (cpuguy83@gmail.com) for readability
38a67a
Sept 2015, updated by Sally O'Malley (somalley@redhat.com)
38a67a
Oct 2016, updated by Addam Hardy (addam.hardy@gmail.com)
38a67a
Aug 2021, converted Dockerfile man page to Containerfile by Dan Walsh (dwalsh@redhat.com)
38a67a
```