pub struct BakeCommand {
pub executor: CommandExecutor,
/* private fields */
}
Expand description
Docker Bake Command Builder
Implements the docker bake
command for building from configuration files
like docker-compose.yml, docker-bake.hcl, or custom bake definitions.
§Docker Bake Overview
The bake command allows you to build multiple targets defined in configuration files, supporting advanced features like:
- Multi-platform builds
- Build matrix configurations
- Shared build contexts
- Variable substitution
- Target dependencies
§Supported File Formats
docker-compose.yml
- Docker Compose service definitionsdocker-bake.hcl
- HCL (HashiCorp
Configuration Language) formatdocker-bake.json
- JSON format- Custom build definition files
§Examples
use docker_wrapper::BakeCommand;
use docker_wrapper::DockerCommand;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Build all targets from docker-compose.yml
let output = BakeCommand::new()
.file("docker-compose.yml")
.execute()
.await?;
println!("Bake success: {}", output.success);
Ok(())
}
Fields§
§executor: CommandExecutor
Command executor for handling raw arguments and execution
Implementations§
Source§impl BakeCommand
impl BakeCommand
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new BakeCommand
instance
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new();
Sourcepub fn target<S: Into<String>>(self, target: S) -> Self
pub fn target<S: Into<String>>(self, target: S) -> Self
Add a target to build
Multiple targets can be specified. If no targets are specified, all targets defined in the bake file will be built.
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.target("web")
.target("api")
.target("worker");
Sourcepub fn targets<I, S>(self, targets: I) -> Self
pub fn targets<I, S>(self, targets: I) -> Self
Add multiple targets to build
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.targets(vec!["web", "api", "worker"]);
Sourcepub fn file<S: Into<String>>(self, file: S) -> Self
pub fn file<S: Into<String>>(self, file: S) -> Self
Add a build definition file
Supports docker-compose.yml, docker-bake.hcl, docker-bake.json, and custom build definition files.
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.file("docker-compose.yml")
.file("custom-bake.hcl");
Sourcepub fn files<I, S>(self, files: I) -> Self
pub fn files<I, S>(self, files: I) -> Self
Add multiple build definition files
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.files(vec!["docker-compose.yml", "override.yml"]);
Sourcepub fn allow<S: Into<String>>(self, resource: S) -> Self
pub fn allow<S: Into<String>>(self, resource: S) -> Self
Allow build to access specified resources
Grants permission to access host resources during build.
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.allow("network.host")
.allow("security.insecure");
Sourcepub fn builder<S: Into<String>>(self, builder: S) -> Self
pub fn builder<S: Into<String>>(self, builder: S) -> Self
Override the configured builder instance
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.builder("mybuilder");
Sourcepub fn call<S: Into<String>>(self, method: S) -> Self
pub fn call<S: Into<String>>(self, method: S) -> Self
Set method for evaluating build
Valid values: “build”, “check”, “outline”, “targets”
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.call("check"); // Validate build configuration
Sourcepub fn check(self) -> Self
pub fn check(self) -> Self
Enable check mode (shorthand for –call=check)
Validates the build configuration without executing the build.
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.check();
Sourcepub fn debug(self) -> Self
pub fn debug(self) -> Self
Enable debug logging
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.debug();
Sourcepub fn list<S: Into<String>>(self, list_type: S) -> Self
pub fn list<S: Into<String>>(self, list_type: S) -> Self
List targets or variables
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.list("targets"); // List all available targets
Sourcepub fn load(self) -> Self
pub fn load(self) -> Self
Load images to Docker daemon (shorthand for –set=*.output=type=docker)
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.load();
Sourcepub fn metadata_file<S: Into<String>>(self, file: S) -> Self
pub fn metadata_file<S: Into<String>>(self, file: S) -> Self
Write build result metadata to a file
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.metadata_file("build-metadata.json");
Sourcepub fn no_cache(self) -> Self
pub fn no_cache(self) -> Self
Do not use cache when building images
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.no_cache();
Sourcepub fn print(self) -> Self
pub fn print(self) -> Self
Print the options without building
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.print();
Sourcepub fn progress<S: Into<String>>(self, progress_type: S) -> Self
pub fn progress<S: Into<String>>(self, progress_type: S) -> Self
Set type of progress output
Valid values: “auto”, “quiet”, “plain”, “tty”, “rawjson”
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.progress("plain");
Sourcepub fn provenance<S: Into<String>>(self, provenance: S) -> Self
pub fn provenance<S: Into<String>>(self, provenance: S) -> Self
Set provenance attestation (shorthand for –set=*.attest=type=provenance)
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.provenance("mode=max");
Sourcepub fn pull(self) -> Self
pub fn pull(self) -> Self
Always attempt to pull all referenced images
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.pull();
Sourcepub fn push(self) -> Self
pub fn push(self) -> Self
Push images to registry (shorthand for –set=*.output=type=registry)
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.push();
Sourcepub fn sbom<S: Into<String>>(self, sbom: S) -> Self
pub fn sbom<S: Into<String>>(self, sbom: S) -> Self
Set SBOM attestation (shorthand for –set=*.attest=type=sbom)
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.sbom("generator=docker/buildkit");
Sourcepub fn set<K: Into<String>, V: Into<String>>(self, key: K, value: V) -> Self
pub fn set<K: Into<String>, V: Into<String>>(self, key: K, value: V) -> Self
Override target value (e.g., “targetpattern.key=value”)
This allows overriding any target configuration at build time.
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.set("web.platform", "linux/amd64,linux/arm64")
.set("*.output", "type=registry");
Sourcepub fn set_values<I, K, V>(self, values: I) -> Self
pub fn set_values<I, K, V>(self, values: I) -> Self
Add multiple target value overrides
§Examples
use std::collections::HashMap;
use docker_wrapper::BakeCommand;
let mut overrides = HashMap::new();
overrides.insert("web.platform".to_string(), "linux/amd64".to_string());
overrides.insert("api.platform".to_string(), "linux/arm64".to_string());
let bake_cmd = BakeCommand::new()
.set_values(overrides);
Sourcepub fn target_count(&self) -> usize
pub fn target_count(&self) -> usize
Get the number of targets
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.target("web")
.target("api");
assert_eq!(bake_cmd.target_count(), 2);
Sourcepub fn get_targets(&self) -> &[String]
pub fn get_targets(&self) -> &[String]
Get the list of targets
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.target("web")
.target("api");
let targets = bake_cmd.get_targets();
assert_eq!(targets, &["web", "api"]);
Sourcepub fn get_files(&self) -> &[String]
pub fn get_files(&self) -> &[String]
Get the list of build definition files
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new()
.file("docker-compose.yml");
let files = bake_cmd.get_files();
assert_eq!(files, &["docker-compose.yml"]);
Sourcepub fn is_push_enabled(&self) -> bool
pub fn is_push_enabled(&self) -> bool
Check if push mode is enabled
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new().push();
assert!(bake_cmd.is_push_enabled());
Sourcepub fn is_load_enabled(&self) -> bool
pub fn is_load_enabled(&self) -> bool
Check if load mode is enabled
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new().load();
assert!(bake_cmd.is_load_enabled());
Sourcepub fn is_dry_run(&self) -> bool
pub fn is_dry_run(&self) -> bool
Check if dry-run mode is enabled (print without building)
§Examples
use docker_wrapper::BakeCommand;
let bake_cmd = BakeCommand::new().print();
assert!(bake_cmd.is_dry_run());
Trait Implementations§
Source§impl Clone for BakeCommand
impl Clone for BakeCommand
Source§fn clone(&self) -> BakeCommand
fn clone(&self) -> BakeCommand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more