pub struct BuildahCommand {
pub program: String,
pub args: Vec<String>,
pub env: HashMap<String, String>,
}Expand description
A buildah command ready for execution
Fields§
§program: StringThe program to execute (typically “buildah”)
args: Vec<String>Command arguments
env: HashMap<String, String>Optional environment variables for the command
Implementations§
Source§impl BuildahCommand
impl BuildahCommand
Sourcepub fn args(self, args: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn args(self, args: impl IntoIterator<Item = impl Into<String>>) -> Self
Add multiple arguments
Sourcepub fn arg_opt(self, flag: &str, value: Option<impl Into<String>>) -> Self
pub fn arg_opt(self, flag: &str, value: Option<impl Into<String>>) -> Self
Add an optional argument (only added if value is Some)
Sourcepub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add an environment variable for command execution
Sourcepub fn to_command_string(&self) -> String
pub fn to_command_string(&self) -> String
Convert to a command line string for display/logging
Sourcepub fn from_image(image: &str) -> Self
pub fn from_image(image: &str) -> Self
Create a new working container from an image
buildah from <image>
Sourcepub fn from_image_named(image: &str, name: &str) -> Self
pub fn from_image_named(image: &str, name: &str) -> Self
Create a new working container from an image with a specific name
buildah from --name <name> <image>
Sourcepub fn from_scratch() -> Self
pub fn from_scratch() -> Self
Create a scratch container
buildah from scratch
Sourcepub fn commit(container: &str, image_name: &str) -> Self
pub fn commit(container: &str, image_name: &str) -> Self
Commit a container to create an image
buildah commit <container> <image>
Sourcepub fn commit_with_opts(
container: &str,
image_name: &str,
format: Option<&str>,
squash: bool,
) -> Self
pub fn commit_with_opts( container: &str, image_name: &str, format: Option<&str>, squash: bool, ) -> Self
Commit with additional options
Sourcepub fn tag(image: &str, new_name: &str) -> Self
pub fn tag(image: &str, new_name: &str) -> Self
Tag an image with a new name
buildah tag <image> <new-name>
Sourcepub fn rmi_force(image: &str) -> Self
pub fn rmi_force(image: &str) -> Self
Forcibly remove an image, even if it is referenced by a manifest list or in use.
buildah rmi -f <image>
Sourcepub fn pull(image: &str, policy: Option<&str>) -> Self
pub fn pull(image: &str, policy: Option<&str>) -> Self
Pull an image from a registry into local storage.
buildah pull [--policy <policy>] <image>
policy controls when the registry is consulted: "newer" only pulls
when the upstream is newer than the local copy, "always" forces a
fresh pull, and "never" (or "missing") is useful for offline builds.
When policy is None, buildah’s default policy applies.
Sourcepub fn push_with_creds(image: &str, creds: Option<&str>) -> Self
pub fn push_with_creds(image: &str, creds: Option<&str>) -> Self
Push an image to a registry, optionally with registry credentials.
buildah requires global/command options to precede the positional
image/destination argument (buildah push [options] IMAGE [DESTINATION])
— passing --creds after the image fails with “no options (–creds) can
be specified after the image or container name”. This builds the option
flags BEFORE the positional image.
Sourcepub fn push_to(image: &str, destination: &str) -> Self
pub fn push_to(image: &str, destination: &str) -> Self
Push an image to a registry with options
buildah push [options] <image> [destination]
Sourcepub fn inspect_format(name: &str, format: &str) -> Self
pub fn inspect_format(name: &str, format: &str) -> Self
Inspect an image or container with format
buildah inspect --format <format> <name>
Sourcepub fn containers() -> Self
pub fn containers() -> Self
List containers
buildah containers
Sourcepub fn run_shell(container: &str, command: &str) -> Self
pub fn run_shell(container: &str, command: &str) -> Self
Run a command in the container (shell form) using the Linux default shell.
buildah run <container> -- /bin/sh -c "<command>"
For OS-aware translation (Windows targets, or honoring a SHELL
override), prefer Self::run_shell_custom or the stateful
DockerfileTranslator.
Sourcepub fn run_shell_custom(
container: &str,
shell: impl IntoIterator<Item = impl AsRef<str>>,
command: &str,
) -> Self
pub fn run_shell_custom( container: &str, shell: impl IntoIterator<Item = impl AsRef<str>>, command: &str, ) -> Self
Run a command in the container (shell form) using an explicit shell.
buildah run <container> -- <shell...> <command>
The shell slice is emitted verbatim before the command argument, e.g.
["cmd.exe", "/S", "/C"] for Windows or ["/bin/bash", "-lc"] for a
bash-login override.
Sourcepub fn run_shell_custom_with_net(
container: &str,
shell: impl IntoIterator<Item = impl AsRef<str>>,
command: &str,
net: Option<RunNetwork>,
) -> Self
pub fn run_shell_custom_with_net( container: &str, shell: impl IntoIterator<Item = impl AsRef<str>>, command: &str, net: Option<RunNetwork>, ) -> Self
Run a command in the container (shell form) using an explicit shell, optionally pinning the network mode.
buildah run [--net=<mode>] <container> -- <shell...> <command>
See Self::run_exec_with_net for the meaning of net.
Sourcepub fn run_shell_for_os(container: &str, command: &str, os: ImageOs) -> Self
pub fn run_shell_for_os(container: &str, command: &str, os: ImageOs) -> Self
Run a command in the container (shell form) using the OS default shell.
Linux → /bin/sh -c, Windows → cmd.exe /S /C.
Sourcepub fn run_exec(container: &str, args: &[String]) -> Self
pub fn run_exec(container: &str, args: &[String]) -> Self
Run a command in the container (exec form)
buildah run <container> -- <args...>
Sourcepub fn run_exec_with_net(
container: &str,
args: &[String],
net: Option<RunNetwork>,
) -> Self
pub fn run_exec_with_net( container: &str, args: &[String], net: Option<RunNetwork>, ) -> Self
Run a command in the container (exec form), optionally pinning the network mode.
buildah run [--net=<mode>] <container> -- <args...>
The --net=<mode> flag MUST precede the container ID — buildah parses
flags up to the first positional and then treats the rest as the
command. When net is None, no --net flag is emitted and buildah
uses its default rootless networking. Use Some(RunNetwork::Host)
when the translator-level host_network override is on, so the
emitted buildah run bypasses CNI/netavark just like the dedicated
RUN instruction path does.
Sourcepub fn run(container: &str, command: &ShellOrExec) -> Self
pub fn run(container: &str, command: &ShellOrExec) -> Self
Run a command based on ShellOrExec
Sourcepub fn run_with_mounts(container: &str, run: &RunInstruction) -> Self
pub fn run_with_mounts(container: &str, run: &RunInstruction) -> Self
Run a command with mount specifications from a RunInstruction.
Buildah requires --mount arguments to appear BEFORE the container ID:
buildah run [--mount=...] <container> -- <command>
This method properly orders the arguments to ensure mounts are applied.
Uses the Linux default shell (/bin/sh -c) for shell-form commands.
For OS-aware translation use Self::run_with_mounts_shell.
Sourcepub fn run_with_mounts_shell(
container: &str,
run: &RunInstruction,
shell: impl IntoIterator<Item = impl AsRef<str>>,
) -> Self
pub fn run_with_mounts_shell( container: &str, run: &RunInstruction, shell: impl IntoIterator<Item = impl AsRef<str>>, ) -> Self
Run a command with mount specifications, using an explicit shell for shell-form commands.
Exec-form commands ignore shell and are emitted verbatim, matching
Docker/Buildah semantics.
Sourcepub fn copy(container: &str, sources: &[String], dest: &str) -> Self
pub fn copy(container: &str, sources: &[String], dest: &str) -> Self
Copy files into the container
buildah copy <container> <src...> <dest>
Sourcepub fn copy_from(
container: &str,
from: &str,
sources: &[String],
dest: &str,
) -> Self
pub fn copy_from( container: &str, from: &str, sources: &[String], dest: &str, ) -> Self
Copy files from another container/image
buildah copy --from=<source> <container> <src...> <dest>
Sourcepub fn copy_empty_dir(container: &str, empty_src: &Path, dest: &str) -> Self
pub fn copy_empty_dir(container: &str, empty_src: &Path, dest: &str) -> Self
Materialize a directory in the container rootfs without running a process inside the container.
Emits buildah copy <container> <empty_src>/. <dest> where
empty_src is an empty host directory. buildah copy creates
<dest> (and its parents) in the rootfs as part of the copy, and
because the source has no entries nothing is actually copied —
the net effect is mkdir -p <dest> on the rootfs, but executed by
buildah’s filesystem code, not by a shell inside the container.
This is the shell-free equivalent of
BuildahCommand::run_exec_with_net(ctr, &["mkdir","-p", dir], …),
usable on distroless / scratch / any base image that lacks
mkdir / /bin/sh. Callers MUST keep the host source directory
alive (and empty) for the lifetime of this command’s execution.
Sourcepub fn copy_instruction(container: &str, copy: &CopyInstruction) -> Self
pub fn copy_instruction(container: &str, copy: &CopyInstruction) -> Self
Copy with all options from CopyInstruction
Sourcepub fn add(container: &str, sources: &[String], dest: &str) -> Self
pub fn add(container: &str, sources: &[String], dest: &str) -> Self
Add files (like copy but with URL support and extraction)
Sourcepub fn add_instruction(container: &str, add: &AddInstruction) -> Self
pub fn add_instruction(container: &str, add: &AddInstruction) -> Self
Add with all options from AddInstruction
Sourcepub fn config_env(container: &str, key: &str, value: &str) -> Self
pub fn config_env(container: &str, key: &str, value: &str) -> Self
Set an environment variable
buildah config --env KEY=VALUE <container>
Sourcepub fn config_envs(container: &str, env: &EnvInstruction) -> Vec<Self>
pub fn config_envs(container: &str, env: &EnvInstruction) -> Vec<Self>
Set multiple environment variables
Sourcepub fn config_workdir(container: &str, dir: &str) -> Self
pub fn config_workdir(container: &str, dir: &str) -> Self
Set the working directory
buildah config --workingdir <dir> <container>
Sourcepub fn config_expose(container: &str, expose: &ExposeInstruction) -> Self
pub fn config_expose(container: &str, expose: &ExposeInstruction) -> Self
Expose a port
buildah config --port <port>/<proto> <container>
Sourcepub fn config_entrypoint_shell(container: &str, command: &str) -> Self
pub fn config_entrypoint_shell(container: &str, command: &str) -> Self
Set the entrypoint (shell form)
buildah config --entrypoint '<command>' <container>
Sourcepub fn config_entrypoint_exec(container: &str, args: &[String]) -> Self
pub fn config_entrypoint_exec(container: &str, args: &[String]) -> Self
Set the entrypoint (exec form)
buildah config --entrypoint '["exe", "arg1"]' <container>
Sourcepub fn config_entrypoint(container: &str, command: &ShellOrExec) -> Self
pub fn config_entrypoint(container: &str, command: &ShellOrExec) -> Self
Set the entrypoint based on ShellOrExec
Sourcepub fn config_cmd_shell(container: &str, command: &str) -> Self
pub fn config_cmd_shell(container: &str, command: &str) -> Self
Set the default command (shell form)
Sourcepub fn config_cmd_exec(container: &str, args: &[String]) -> Self
pub fn config_cmd_exec(container: &str, args: &[String]) -> Self
Set the default command (exec form)
Sourcepub fn config_cmd(container: &str, command: &ShellOrExec) -> Self
pub fn config_cmd(container: &str, command: &ShellOrExec) -> Self
Set the default command based on ShellOrExec
Sourcepub fn config_user(container: &str, user: &str) -> Self
pub fn config_user(container: &str, user: &str) -> Self
Set the user
buildah config --user <user> <container>
Sourcepub fn config_label(container: &str, key: &str, value: &str) -> Self
pub fn config_label(container: &str, key: &str, value: &str) -> Self
Set a label
buildah config --label KEY=VALUE <container>
Sourcepub fn config_labels(
container: &str,
labels: &HashMap<String, String>,
) -> Vec<Self>
pub fn config_labels( container: &str, labels: &HashMap<String, String>, ) -> Vec<Self>
Set multiple labels
Sourcepub fn config_volume(container: &str, path: &str) -> Self
pub fn config_volume(container: &str, path: &str) -> Self
Set volumes
buildah config --volume <path> <container>
Sourcepub fn config_stopsignal(container: &str, signal: &str) -> Self
pub fn config_stopsignal(container: &str, signal: &str) -> Self
Set the stop signal
buildah config --stop-signal <signal> <container>
Sourcepub fn config_shell(container: &str, shell: &[String]) -> Self
pub fn config_shell(container: &str, shell: &[String]) -> Self
Set the shell
buildah config --shell '["shell", "args"]' <container>
Sourcepub fn config_healthcheck(
container: &str,
healthcheck: &HealthcheckInstruction,
) -> Self
pub fn config_healthcheck( container: &str, healthcheck: &HealthcheckInstruction, ) -> Self
Set healthcheck
Sourcepub fn manifest_create(name: &str) -> Self
pub fn manifest_create(name: &str) -> Self
Create a new manifest list.
buildah manifest create <name>
Sourcepub fn manifest_add(list: &str, image: &str) -> Self
pub fn manifest_add(list: &str, image: &str) -> Self
Add an image to a manifest list.
buildah manifest add <list> <image>
Sourcepub fn manifest_push(list: &str, destination: &str) -> Self
pub fn manifest_push(list: &str, destination: &str) -> Self
Push a manifest list and all referenced images.
buildah manifest push --all <list> <destination>
Sourcepub fn manifest_push_with_creds(
list: &str,
destination: &str,
creds: Option<&str>,
) -> Self
pub fn manifest_push_with_creds( list: &str, destination: &str, creds: Option<&str>, ) -> Self
Push a manifest list, optionally with registry credentials.
buildah requires options to precede the positional list/destination
arguments (buildah manifest push [options] LISTNAME DESTINATION) —
passing --creds after the list/destination fails with “no options
(–creds) can be specified after the image or container name”. This
builds every flag (--all, --creds) BEFORE the positionals.
Sourcepub fn manifest_rm(list: &str) -> Self
pub fn manifest_rm(list: &str) -> Self
Remove a manifest list.
buildah manifest rm <list>
Sourcepub fn from_instruction(container: &str, instruction: &Instruction) -> Vec<Self>
pub fn from_instruction(container: &str, instruction: &Instruction) -> Vec<Self>
Convert a Dockerfile instruction to buildah command(s) using the Linux
default shell (/bin/sh -c) and POSIX mkdir -p semantics.
This is a convenience wrapper around DockerfileTranslator with
target_os = ImageOs::Linux and no SHELL override. It preserves the
historical byte-for-byte behavior for every call site that existed
before OS-aware translation landed in Phase L-3.
For Windows targets or when a Dockerfile-level SHELL instruction
needs to be honored across subsequent RUNs, construct a
DockerfileTranslator explicitly and call
DockerfileTranslator::translate.
Some instructions map to multiple buildah commands (e.g., multiple
ENV vars, or WORKDIR emitting both mkdir and config --workingdir).
Sourcepub fn build(
dockerfile_path: &Path,
context: &Path,
options: &BuildOptions,
effective_build_args: &BTreeMap<String, String>,
ssh_ids: &[String],
secret_ids: &[String],
) -> Self
pub fn build( dockerfile_path: &Path, context: &Path, options: &BuildOptions, effective_build_args: &BTreeMap<String, String>, ssh_ids: &[String], secret_ids: &[String], ) -> Self
Build an image with buildah’s native frontend: buildah build.
This drives buildah’s own Dockerfile parser/executor over a
pre-rendered Dockerfile (dockerfile_path, written into context so
COPY/ADD and the -f path resolve), instead of the legacy
buildah from → per-instruction translate → buildah commit loop.
Flag map:
| source | flag |
|---|---|
dockerfile_path | -f <path> |
context | trailing positional |
each options.tags[i] | --tag <t> |
options.target | --target <s> |
options.no_cache | --no-cache |
options.layers (default true) | --layers (omitted when false) |
options.squash | --squash |
options.format | --format oci|docker |
options.platform (a,b) | --platform a,b |
effective_build_args (K=V) | --build-arg K=V |
options.host_network | --network=host |
options.pull Newer/Always/Never | --pull=ifnewer|always|never |
options.cache_from/cache_to/cache_ttl | --cache-from/-to/-ttl |
| rootless (uid != 0, Unix) | --isolation=chroot |
| each distinct RUN ssh id | --ssh <id> |
effective_build_args is the caller-merged map of options.build_args
overlaid with options.pipeline_vars; ssh_ids is the de-duplicated,
ordered list of RUN --mount=type=ssh ids discovered in the IR.
Trait Implementations§
Source§impl Clone for BuildahCommand
impl Clone for BuildahCommand
Source§fn clone(&self) -> BuildahCommand
fn clone(&self) -> BuildahCommand
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BuildahCommand
impl RefUnwindSafe for BuildahCommand
impl Send for BuildahCommand
impl Sync for BuildahCommand
impl Unpin for BuildahCommand
impl UnsafeUnpin for BuildahCommand
impl UnwindSafe for BuildahCommand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request