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