Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Bentoml BentoML Container Build

From Leeroopedia
Revision as of 12:06, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Bentoml_BentoML_Container_Build.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Sources Domains Last Updated
BentoML, BentoML Containerization ML_Serving, Containerization, OCI_Images 2026-02-13 15:00 GMT

Overview

The bentoml.container.build() function wraps multiple container build backends (Docker, Podman, Buildx, etc.) to convert a Bento artifact into an OCI-compliant container image.

Description

This function serves as a unified wrapper over pluggable container build backends. It accepts a Bento tag, selects the appropriate backend, generates a Dockerfile from the Bento's environment specification, and invokes the backend's build command. Additional features (such as gRPC or tracing support) can be enabled via the features parameter, which installs optional dependency groups into the container.

Usage

Call after building a Bento to produce a container image. Typically invoked via the CLI (bentoml containerize) or programmatically for CI/CD automation.

Code Reference

Source Location: Repository: bentoml/BentoML, File: src/bentoml/container.py (L362-406)

Signature:

def build(
    bento_tag: Tag | str,
    backend: DefaultBuilder = "docker",
    image_tag: tuple[str] = None,
    features: Sequence[str] = None,
    **kwargs,
) -> Any

Import:

import bentoml

bentoml.container.build(...)

I/O Contract

Inputs:

Parameter Type Required Description
bento_tag Tag or str Yes Tag of the built Bento artifact (e.g., "my-service:abc123")
backend DefaultBuilder No Container build backend (default "docker")
image_tag tuple[str] No One or more image tags to apply to the built image
features Sequence[str] No Optional feature groups to install (e.g., "tracing", "grpc")
**kwargs dict No Additional backend-specific arguments

Backend Options:

Backend Description Key Use Case
"docker" Standard Docker daemon build Default local builds
"buildx" Docker Buildx (BuildKit) Multi-platform images
"podman" Podman rootless build Rootless / daemonless environments
"buildah" Buildah OCI image builder Daemonless OCI builds
"nerdctl" containerd-native CLI containerd environments
"buildctl" BuildKit low-level client Advanced BuildKit usage

Outputs:

  • Container image built and tagged in the selected backend's image store

Usage Examples

Example 1 -- Basic Docker build:

import bentoml

bentoml.container.build(
    "my-service:latest",
    backend="docker",
    image_tag=("my-registry/my-service:v1",),
)

Example 2 -- Multi-platform build with Buildx:

import bentoml

bentoml.container.build(
    "my-service:abc123",
    backend="buildx",
    image_tag=("my-service:latest",),
    platform="linux/amd64,linux/arm64",
)

Example 3 -- Build with optional features:

import bentoml

bentoml.container.build(
    "my-service:latest",
    features=["grpc", "tracing"],
)

Example 4 -- Rootless build with Podman:

import bentoml

bentoml.container.build(
    "my-service:latest",
    backend="podman",
    image_tag=("localhost/my-service:v1",),
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment