Skip to main content

BuildahCommand

Struct BuildahCommand 

Source
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: String

The program to execute (typically “buildah”)

§args: Vec<String>

Command arguments

§env: HashMap<String, String>

Optional environment variables for the command

Implementations§

Source§

impl BuildahCommand

Source

pub fn new(subcommand: &str) -> Self

Create a new buildah command

Source

pub fn arg(self, arg: impl Into<String>) -> Self

Add an argument

Source

pub fn args(self, args: impl IntoIterator<Item = impl Into<String>>) -> Self

Add multiple arguments

Source

pub fn arg_opt(self, flag: &str, value: Option<impl Into<String>>) -> Self

Add an optional argument (only added if value is Some)

Source

pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self

Add an environment variable for command execution

Source

pub fn to_command_string(&self) -> String

Convert to a command line string for display/logging

Source

pub fn from_image(image: &str) -> Self

Create a new working container from an image

buildah from <image>

Source

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>

Source

pub fn from_scratch() -> Self

Create a scratch container

buildah from scratch

Source

pub fn rm(container: &str) -> Self

Remove a working container

buildah rm <container>

Source

pub fn commit(container: &str, image_name: &str) -> Self

Commit a container to create an image

buildah commit <container> <image>

Source

pub fn commit_with_opts( container: &str, image_name: &str, format: Option<&str>, squash: bool, ) -> Self

Commit with additional options

Source

pub fn tag(image: &str, new_name: &str) -> Self

Tag an image with a new name

buildah tag <image> <new-name>

Source

pub fn rmi(image: &str) -> Self

Remove an image

buildah rmi <image>

Source

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>

Source

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.

Source

pub fn push(image: &str) -> Self

Push an image to a registry

buildah push <image>

Source

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.

Source

pub fn push_to(image: &str, destination: &str) -> Self

Push an image to a registry with options

buildah push [options] <image> [destination]

Source

pub fn inspect(name: &str) -> Self

Inspect an image or container

buildah inspect <name>

Source

pub fn inspect_format(name: &str, format: &str) -> Self

Inspect an image or container with format

buildah inspect --format <format> <name>

Source

pub fn images() -> Self

List images

buildah images

Source

pub fn containers() -> Self

List containers

buildah containers

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn run_exec(container: &str, args: &[String]) -> Self

Run a command in the container (exec form)

buildah run <container> -- <args...>

Source

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.

Source

pub fn run(container: &str, command: &ShellOrExec) -> Self

Run a command based on ShellOrExec

Source

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.

Source

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.

Source

pub fn copy(container: &str, sources: &[String], dest: &str) -> Self

Copy files into the container

buildah copy <container> <src...> <dest>

Source

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>

Source

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.

Source

pub fn copy_instruction(container: &str, copy: &CopyInstruction) -> Self

Copy with all options from CopyInstruction

Source

pub fn add(container: &str, sources: &[String], dest: &str) -> Self

Add files (like copy but with URL support and extraction)

Source

pub fn add_instruction(container: &str, add: &AddInstruction) -> Self

Add with all options from AddInstruction

Source

pub fn config_env(container: &str, key: &str, value: &str) -> Self

Set an environment variable

buildah config --env KEY=VALUE <container>

Source

pub fn config_envs(container: &str, env: &EnvInstruction) -> Vec<Self>

Set multiple environment variables

Source

pub fn config_workdir(container: &str, dir: &str) -> Self

Set the working directory

buildah config --workingdir <dir> <container>

Source

pub fn config_expose(container: &str, expose: &ExposeInstruction) -> Self

Expose a port

buildah config --port <port>/<proto> <container>

Source

pub fn config_entrypoint_shell(container: &str, command: &str) -> Self

Set the entrypoint (shell form)

buildah config --entrypoint '<command>' <container>

Source

pub fn config_entrypoint_exec(container: &str, args: &[String]) -> Self

Set the entrypoint (exec form)

buildah config --entrypoint '["exe", "arg1"]' <container>

Source

pub fn config_entrypoint(container: &str, command: &ShellOrExec) -> Self

Set the entrypoint based on ShellOrExec

Source

pub fn config_cmd_shell(container: &str, command: &str) -> Self

Set the default command (shell form)

Source

pub fn config_cmd_exec(container: &str, args: &[String]) -> Self

Set the default command (exec form)

Source

pub fn config_cmd(container: &str, command: &ShellOrExec) -> Self

Set the default command based on ShellOrExec

Source

pub fn config_user(container: &str, user: &str) -> Self

Set the user

buildah config --user <user> <container>

Source

pub fn config_label(container: &str, key: &str, value: &str) -> Self

Set a label

buildah config --label KEY=VALUE <container>

Source

pub fn config_labels( container: &str, labels: &HashMap<String, String>, ) -> Vec<Self>

Set multiple labels

Source

pub fn config_volume(container: &str, path: &str) -> Self

Set volumes

buildah config --volume <path> <container>

Source

pub fn config_stopsignal(container: &str, signal: &str) -> Self

Set the stop signal

buildah config --stop-signal <signal> <container>

Source

pub fn config_shell(container: &str, shell: &[String]) -> Self

Set the shell

buildah config --shell '["shell", "args"]' <container>

Source

pub fn config_healthcheck( container: &str, healthcheck: &HealthcheckInstruction, ) -> Self

Set healthcheck

Source

pub fn manifest_create(name: &str) -> Self

Create a new manifest list.

buildah manifest create <name>

Source

pub fn manifest_add(list: &str, image: &str) -> Self

Add an image to a manifest list.

buildah manifest add <list> <image>

Source

pub fn manifest_push(list: &str, destination: &str) -> Self

Push a manifest list and all referenced images.

buildah manifest push --all <list> <destination>

Source

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.

Source

pub fn manifest_rm(list: &str) -> Self

Remove a manifest list.

buildah manifest rm <list>

Source

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).

Source

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:

sourceflag
dockerfile_path-f <path>
contexttrailing 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

Source§

fn clone(&self) -> BuildahCommand

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BuildahCommand

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more