2018-03-20 17:41:19 +08:00
# buildah-run "1" "March 2017" "buildah"
2017-03-29 03:37:24 +08:00
## NAME
2018-04-26 21:01:15 +08:00
buildah\-run - Run a command inside of the container.
2017-03-29 03:37:24 +08:00
## SYNOPSIS
2018-06-30 03:39:36 +08:00
**buildah run** [*options*] [**--**] *container* *command*
2017-03-29 03:37:24 +08:00
## DESCRIPTION
2017-04-14 03:42:04 +08:00
Launches a container and runs the specified command in that container using the
container's root filesystem as a root filesystem, using configuration settings
inherited from the container's image or as specified using previous calls to
2018-02-18 03:23:06 +08:00
the *buildah config* command. To execute *buildah run* within an
interactive shell, specify the --tty option.
2017-03-29 03:37:24 +08:00
## OPTIONS
2022-03-24 20:03:06 +08:00
2019-01-19 04:39:58 +08:00
**--add-history**
Add an entry to the history which will note what command is being invoked.
Defaults to false.
Note: You can also override the default value of --add-history by setting the
BUILDAH\_HISTORY environment variable. `export BUILDAH_HISTORY=true`
2018-06-05 05:36:26 +08:00
**--cap-add**=*CAP\_xxx*
Add the specified capability to the set of capabilities which will be granted
to the specified command.
Certain capabilities are granted by default; this option can be used to add
more beyond the defaults, which may have been modified by ** --cap-add** and
**--cap-drop** options used with the *buildah from* invocation which created
the container.
**--cap-drop**=*CAP\_xxx*
Add the specified capability from the set of capabilities which will be granted
to the specified command.
The CAP\_AUDIT\_WRITE, CAP\_CHOWN, CAP\_DAC\_OVERRIDE, CAP\_FOWNER,
CAP\_FSETID, CAP\_KILL, CAP\_MKNOD, CAP\_NET\_BIND\_SERVICE, CAP\_SETFCAP,
CAP\_SETGID, CAP\_SETPCAP, CAP\_SETUID, and CAP\_SYS\_CHROOT capabilities are
granted by default; this option can be used to remove them from the defaults,
which may have been modified by ** --cap-add** and ** --cap-drop** options used
with the *buildah from* invocation which created the container.
If a capability is specified to both the ** --cap-add** and ** --cap-drop**
options, it will be dropped, regardless of the order in which the options were
given.
2021-11-19 04:20:50 +08:00
**--cgroupns** *how*
Sets the configuration for the cgroup namespaces for the container.
The configured value can be "" (the empty string) or "private" to indicate
that a new cgroup namespace should be created, or it can be "host" to indicate
that the cgroup namespace in which `buildah` itself is being run should be reused.
2022-03-24 20:03:06 +08:00
**--contextdir** *directory*
Allows setting context directory for current RUN invocation. Specifying a context
directory causes RUN context to consider context directory as root directory for
specified source in `--mount` of type 'bind'.
2021-06-23 04:45:09 +08:00
**--env**, ** -e** *env=value*
Temporarily add a value (e.g. env=*value*) to the environment for the running
process. Unlike `buildah config --env` , the environment will not persist to
later calls to `buildah run` or to the built image. Can be used multiple times.
2017-09-21 19:39:39 +08:00
**--hostname**
2018-06-15 03:41:05 +08:00
2017-09-21 19:39:39 +08:00
Set the hostname inside of the running container.
2017-07-07 12:41:31 +08:00
2018-03-13 01:53:12 +08:00
**--ipc** *how*
Sets the configuration for the IPC namespaces for the container.
2020-08-04 22:13:17 +08:00
The configured value can be "" (the empty string) or "private" to indicate
2018-03-13 01:53:12 +08:00
that a new IPC namespace should be created, or it can be "host" to indicate
that the IPC namespace in which `buildah` itself is being run should be reused,
or it can be the path to an IPC namespace which is already in use by another
process.
2018-05-12 01:00:14 +08:00
**--isolation** *type*
2018-07-19 02:59:20 +08:00
Controls what type of isolation is used for running the process. Recognized
types include *oci* (OCI-compatible runtime, the default), *rootless*
2018-10-31 20:36:25 +08:00
(OCI-compatible runtime invoked using a modified configuration, with
2021-06-03 04:22:28 +08:00
*--no-new-keyring* added to its *create* invocation, reusing the host's network
and UTS namespaces, and creating private IPC, PID, mount, and user namespaces;
the default for unprivileged users), and *chroot* (an internal wrapper that
leans more toward chroot(1) than container technology, reusing the host's
control group, network, IPC, and PID namespaces, and creating private mount and
UTS namespaces, and creating user namespaces only when they're required for ID
mapping).
2018-05-12 01:00:14 +08:00
Note: You can also override the default isolation type by setting the
BUILDAH\_ISOLATION environment variable. `export BUILDAH_ISOLATION=oci`
2019-06-20 02:17:11 +08:00
**--mount**=*type=TYPE,TYPE-SPECIFIC-OPTION[,...]*
Attach a filesystem mount to the container
2021-10-07 16:27:17 +08:00
Current supported mount TYPES are bind, cache, secret and tmpfs. < sup > [[1]](#Footnote1)< / sup >
2019-06-20 02:17:11 +08:00
e.g.
type=bind,source=/path/on/host,destination=/path/in/container
type=tmpfs,tmpfs-size=512M,destination=/path/in/container
2021-10-07 16:27:17 +08:00
type=cache,target=/path/in/container
2019-06-20 02:17:11 +08:00
Common Options:
2021-10-18 13:51:51 +08:00
· src, source: mount source spec for bind and volume. Mandatory for bind. If `from` is specified, `src` is the subpath in the `from` field.
2019-06-20 02:17:11 +08:00
· dst, destination, target: mount destination spec.
· ro, read-only: true or false (default).
Options specific to bind:
· bind-propagation: shared, slave, private, rshared, rslave, or rprivate(default). See also mount(2).
2019-07-18 05:55:10 +08:00
2019-06-20 02:17:11 +08:00
. bind-nonrecursive: do not setup a recursive bind mount. By default it is recursive.
2021-10-18 13:51:51 +08:00
· from: stage or image name for the root of the source. Defaults to the build context.
2019-06-20 02:17:11 +08:00
Options specific to tmpfs:
· tmpfs-size: Size of the tmpfs mount in bytes. Unlimited by default in Linux.
· tmpfs-mode: File mode of the tmpfs in octal. (e.g. 700 or 0700.) Defaults to 1777 in Linux.
2021-10-08 15:55:37 +08:00
· tmpcopyup: Path that is shadowed by the tmpfs mount is recursively copied up to the tmpfs itself.
2021-10-07 16:27:17 +08:00
Options specific to secret:
· id: the identifier for the secret passed into the `buildah bud --secret` or `podman build --secret` command.
Options specific to cache:
· id: Create a separate cache directory for a particular id.
· mode: File mode for new cache directory in octal. Default 0755.
· ro, readonly: read only cache if set.
· uid: uid for cache directory.
· gid: gid for cache directory.
2021-10-18 13:51:51 +08:00
· from: stage name for the root of the source. Defaults to host cache directory.
2020-08-04 22:13:17 +08:00
**--network**, ** --net**=*mode*
2018-03-13 01:53:12 +08:00
Sets the configuration for the network namespace for the container.
2020-08-04 22:13:17 +08:00
- **none**: no networking;
2020-11-20 22:52:51 +08:00
- **host**: use the host network stack. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure;
2020-08-04 22:13:17 +08:00
- **ns:**_path_: path to a network namespace to join;
- `private` : create a new namespace for the container (default)
2018-03-13 01:53:12 +08:00
2022-03-24 20:03:06 +08:00
**--no-hosts**
Do not create _/etc/hosts_ for the container.
By default, Buildah manages _/etc/hosts_ , adding the container's own IP address.
**--no-hosts** disables this, and the image's _/etc/hosts_ will be preserved unmodified.
**--no-pivot**
Do not use pivot root to jail process inside rootfs. This should be used
whenever the rootfs is on top of a ramdisk.
Note: You can make this option the default by setting the BUILDAH\_NOPIVOT
environment variable. `export BUILDAH_NOPIVOT=true`
2018-03-13 01:53:12 +08:00
**--pid** *how*
Sets the configuration for the PID namespace for the container.
2020-08-04 22:13:17 +08:00
The configured value can be "" (the empty string) or "private" to indicate
2018-03-13 01:53:12 +08:00
that a new PID namespace should be created, or it can be "host" to indicate
that the PID namespace in which `buildah` itself is being run should be reused,
or it can be the path to a PID namespace which is already in use by another
process.
2017-04-14 03:42:04 +08:00
**--runtime** *path*
2019-08-28 04:31:34 +08:00
The *path* to an alternate OCI-compatible runtime. Default is `runc` , or `crun` when machine is configured to use cgroups V2.
2018-06-13 05:21:08 +08:00
2018-06-15 03:41:05 +08:00
Note: You can also override the default runtime by setting the BUILDAH\_RUNTIME
2019-08-28 04:31:34 +08:00
environment variable. `export BUILDAH_RUNTIME=/usr/bin/crun`
2017-03-29 03:37:24 +08:00
2017-04-14 03:42:04 +08:00
**--runtime-flag** *flag*
2017-03-29 03:37:24 +08:00
2017-07-10 13:50:12 +08:00
Adds global flags for the container runtime. To list the supported flags, please
2019-08-28 04:31:34 +08:00
consult the manpages of the selected container runtime.
2018-01-31 01:08:18 +08:00
Note: Do not pass the leading `--` to the flag. To pass the runc flag `--log-format json`
to buildah run, the option given would be `--runtime-flag log-format=json` .
2017-03-29 03:37:24 +08:00
2022-03-24 20:03:06 +08:00
**--tty**, ** --terminal**, ** -t**
2017-09-21 19:39:39 +08:00
By default a pseudo-TTY is allocated only when buildah's standard input is
2017-10-02 21:01:45 +08:00
attached to a pseudo-TTY. Setting the `--tty` option to `true` will cause a
pseudo-TTY to be allocated inside the container connecting the user's "terminal"
with the stdin and stdout stream of the container. Setting the `--tty` option to
2017-09-21 19:39:39 +08:00
`false` will prevent the pseudo-TTY from being allocated.
2018-03-13 01:53:12 +08:00
**--user** *user* [:*group*]
Set the *user* to be used for running the command in the container.
The user can be specified as a user name
or UID, optionally followed by a group name or GID, separated by a colon (':').
If names are used, the container should include entries for those names in its
*/etc/passwd* and */etc/group* files.
**--uts** *how*
Sets the configuration for the UTS namespace for the container.
2020-08-04 22:13:17 +08:00
The configured value can be "" (the empty string) or "private" to indicate
2018-03-13 01:53:12 +08:00
that a new UTS namespace should be created, or it can be "host" to indicate
that the UTS namespace in which `buildah` itself is being run should be reused,
or it can be the path to a UTS namespace which is already in use by another
process.
New CI check: xref --help vs man pages
Run 'buildah --help', recursively against all subcommands,
then cross-reference the results against docs/buildah*.md.
Report differences in subcommands and/or flags.
The majority of the changes in this PR are trivial (see
below) but a handful may be controversial and require
careful review:
* Making 'bud' the default output of 'buildah help',
with 'build-using-dockerfile' as an alias. This is
the inverse of the situation until now: buildah
would list build-using-dockerfile as the primary
name. The man page, OTOH, lists 'bud'. The source
file name is 'bud'. I suspect that most people
type 'bud'. So, for consistency, I choose to make
'bud' the default visible command.
* add --encryption-key and --encrypt-layer documentation
to buildah-commit.md, and --encrypt-layer to -push.md.
Please double-check the wording here.
* remove --notruncate from buildah-images.md. The option
does not exist (although there is a TODO comment in
the code). If it should exist, it is left to the
reader to implement. I would humbly suggest that this
is a good idea, for consistency with buildah containers.
* remove --shm-size from buildah-pull.md. The option
does not exist, and I suspect this was a copy-paste error.
* remove --security-opt from run.go. It was unimplemented
and undocumented.
* remove --userns-[gu]id-map from buildah-bud.md. These
are global options, not bud options, and are documented
well enough in buildah.bud.
Trivial (IMO) changes:
* split options in man pages, from '**--foo, -f**'
to '**--foo**, **-f**'. This conforms with the style
used in podman man pages.
* add missing one-letter aliases (usually "-q", "-a")
* add missing man page entries for some easy options
* sort out-of-order subcommand listings in man pages
Finally, do note that this is a copy-and-alter duplicate of the
original script in podman, and that is horrible. In an ideal
world I would've been able to refactor the podman version into
something usable on both repos (and then more). It turns out the
differences in man page format and in special-case handling are
too broad to let me do a clean refactor.
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-09-21 22:51:19 +08:00
**--volume**, ** -v** *source* :*destination*:*options*
2018-04-30 06:36:35 +08:00
Create a bind mount. If you specify, ` -v /HOST-DIR:/CONTAINER-DIR` , Buildah
bind mounts `/HOST-DIR` in the host to `/CONTAINER-DIR` in the Buildah
2020-07-21 01:29:29 +08:00
container. The `OPTIONS` are a comma delimited list and can be: < sup > [[1]](#Footnote1)</ sup >
2018-04-30 06:36:35 +08:00
* [rw|ro]
2020-11-18 22:50:53 +08:00
* [U]
2018-04-30 06:36:35 +08:00
* [z|Z]
* [`[r]shared`|`[r]slave`|`[r]private`]
The `CONTAINER-DIR` must be an absolute path such as `/src/docs` . The `HOST-DIR`
must be an absolute path as well. Buildah bind-mounts the `HOST-DIR` to the
path you specify. For example, if you supply `/foo` as the host path,
Buildah copies the contents of `/foo` to the container filesystem on the host
and bind mounts that into the container.
You can specify multiple ** -v** options to mount one or more mounts to a
container.
2020-11-18 22:50:53 +08:00
`Write Protected Volume Mounts`
2018-04-30 06:36:35 +08:00
You can add the `:ro` or `:rw` suffix to a volume to mount it read-only or
read-write mode, respectively. By default, the volumes are mounted read-write.
See examples.
2020-11-18 22:50:53 +08:00
`Chowning Volume Mounts`
By default, Buildah does not change the owner and group of source volume directories mounted into containers. If a container is created in a new user namespace, the UID and GID in the container may correspond to another UID and GID on the host.
The `:U` suffix tells Buildah to use the correct host UID and GID based on the UID and GID within the container, to change the owner and group of the source volume.
`Labeling Volume Mounts`
2018-04-30 06:36:35 +08:00
Labeling systems like SELinux require that proper labels are placed on volume
content mounted into a container. Without a label, the security system might
prevent the processes running inside the container from using the content. By
default, Buildah does not change the labels set by the OS.
To change a label in the container context, you can add either of two suffixes
`:z` or `:Z` to the volume mount. These suffixes tell Buildah to relabel file
objects on the shared volumes. The `z` option tells Buildah that two containers
share the volume content. As a result, Buildah labels the content with a shared
content label. Shared volume labels allow all containers to read/write content.
The `Z` option tells Buildah to label the content with a private unshared label.
Only the current container can use a private volume.
By default bind mounted volumes are `private` . That means any mounts done
inside container will not be visible on the host and vice versa. This behavior can
2018-09-19 05:07:10 +08:00
be changed by specifying a volume mount propagation property.
2018-04-30 06:36:35 +08:00
When the mount propagation policy is set to `shared` , any mounts completed inside
the container on that volume will be visible to both the host and container. When
the mount propagation policy is set to `slave` , one way mount propagation is enabled
and any mounts completed on the host for that volume will be visible only inside of the container.
To control the mount propagation property of the volume use the `:[r]shared` ,
`:[r]slave` or `:[r]private` propagation flag. The propagation property can
be specified only for bind mounted volumes and not for internal volumes or
named volumes. For mount propagation to work on the source mount point (the mount point
where source dir is mounted on) it has to have the right propagation properties. For
shared volumes, the source mount point has to be shared. And for slave volumes,
2020-07-21 01:29:29 +08:00
the source mount has to be either shared or slave. < sup > [[1]](#Footnote1)< / sup >
2018-04-30 06:36:35 +08:00
Use `df <source-dir>` to determine the source mount and then use
`findmnt -o TARGET,PROPAGATION <source-mount-dir>` to determine propagation
properties of source mount, if `findmnt` utility is not available, the source mount point
can be determined by looking at the mount entry in `/proc/self/mountinfo` . Look
2020-12-22 00:19:56 +08:00
at `optional fields` and see if any propagation properties are specified.
2018-04-30 06:36:35 +08:00
`shared:X` means the mount is `shared` , `master:X` means the mount is `slave` and if
2020-07-21 01:29:29 +08:00
nothing is there that means the mount is `private` . < sup > [[1]](#Footnote1)</ sup >
2018-04-30 06:36:35 +08:00
To change propagation properties of a mount point use the `mount` command. For
example, to bind mount the source directory `/foo` do
`mount --bind /foo /foo` and `mount --make-private --make-shared /foo` . This
will convert /foo into a `shared` mount point. The propagation properties of the source
mount can be changed directly. For instance if `/` is the source mount for
`/foo` , then use `mount --make-shared /` to convert `/` into a `shared` mount.
2017-06-13 22:20:26 +08:00
2021-06-23 04:45:09 +08:00
**--workingdir** *directory*
Temporarily set the working *directory* for the running process. Unlike
`buildah config --workingdir` , the workingdir will not persist to later
calls to `buildah run` or the built image.
2018-03-13 01:53:12 +08:00
2018-02-18 03:23:06 +08:00
NOTE: End parsing of options with the `--` option, so that other
options can be passed to the command inside of the container.
2017-07-18 05:09:30 +08:00
2017-03-29 03:37:24 +08:00
## EXAMPLE
2017-04-14 03:42:04 +08:00
2017-07-18 05:09:30 +08:00
buildah run containerID -- ps -auxw
2017-04-14 03:42:04 +08:00
2018-03-30 16:23:13 +08:00
buildah run --hostname myhost containerID -- ps -auxw
2017-09-21 19:39:39 +08:00
2018-08-16 00:07:10 +08:00
buildah run containerID -- sh -c 'echo $PATH'
2018-03-30 16:23:13 +08:00
buildah run --runtime-flag log-format=json containerID /bin/bash
2018-01-31 01:08:18 +08:00
2018-03-30 16:23:13 +08:00
buildah run --runtime-flag debug containerID /bin/bash
2017-03-29 03:37:24 +08:00
2018-03-30 16:23:13 +08:00
buildah run --tty containerID /bin/bash
2017-10-02 21:01:45 +08:00
2018-03-30 16:23:13 +08:00
buildah run --tty=false containerID ls /
2017-10-02 21:01:45 +08:00
2018-04-30 06:36:35 +08:00
buildah run --volume /path/on/host:/path/in/container:ro,z containerID sh
2020-11-18 22:50:53 +08:00
buildah run -v /path/on/host:/path/in/container:z,U containerID sh
2019-06-20 02:17:11 +08:00
buildah run --mount type=bind,src=/tmp/on:host,dst=/in:container,ro containerID sh
2017-03-29 03:37:24 +08:00
## SEE ALSO
2019-08-28 04:31:34 +08:00
buildah(1), buildah-from(1), buildah-config(1), namespaces(7), pid\_namespaces(7), crun(1), runc(8)
2020-07-21 01:29:29 +08:00
## FOOTNOTES
< a name = "Footnote1" > 1</ a > : The Buildah project is committed to inclusivity, a core value of open source. The `master` and `slave` mount propagation terminology used here is problematic and divisive, and should be changed. However, these terms are currently used within the Linux kernel and must be used as-is at this time. When the kernel maintainers rectify this usage, Buildah will follow suit immediately.