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