Packaging and Containerization
Use this sub-skill when the task is about turning a BentoML Service into a Bento artifact or OCI image: bentoml build, bentoml.build(...), bentofile.yaml, pyproject.toml [tool.bentoml.build], dependency/runtime image settings, file inclusion, local Bento store operations, or bentoml containerize.
Do not use this sub-skill for writing the Service/API itself, running clients or servers, BentoCloud deployment, or framework-specific model import/export details. Route those to service-authoring, serving-and-clients, cli-and-cloud, or model-management.
Fast Path
- Identify the entry Service import path, usually
service:ClassNamefor a class decorated with@bentoml.serviceormodule:svcfor an exported service object. - Prefer runtime image configuration in Python with
bentoml.images.Image(...)attached to@bentoml.service(image=...)for new SDK Services. - Use
bentofile.yamlor[tool.bentoml.build]when the project needs declarative build metadata, file patterns, models, or compatibility with existing workflows. - Run safe local validation before building: parse the YAML, check required files, inspect include/exclude patterns, and confirm dependency files exist.
- Build with
bentoml build,bentoml build -f path/to/bentofile.yaml BUILD_CTX, orbentoml.build(...). - Containerize only when Docker or another OCI backend is available:
bentoml containerize BENTO_TAGorbentoml build --containerize.
Safe Local Checks
python scripts/validate_bentofile.py bentofile.yaml --project-dir .validates field shapes, required paths, and common packaging mistakes without running BentoML, Docker, network access, or dependency resolution.python scripts/create_minimal_bentofile.py --service service:MyService --package numpy --include service.pyprints a starterbentofile.yamlto stdout or writes it with--output bentofile.yaml.bentoml build --bentofile bentofile.yaml --name NAME --version VERSION .creates a Bento in the local Bento store and may resolve dependencies; treat it as more expensive than static validation.bentoml containerize BENTO_TAG --platform linux/amd64requires a container backend and may pull base images or run Docker/BuildKit.
Core Workflows
- Authoring field-level build files: see
references/bentofile-reference.md. - Choosing CLI/API/container commands and build contexts: see
references/workflows.md. - Diagnosing build and image failures: see
references/troubleshooting.md.
Minimal Examples
A minimal bentofile.yaml:
service: "service:MyService"
include:
- "service.py"
python:
packages:
- "numpy"
docker:
python_version: "3.11"
Equivalent direct build API shape:
import bentoml
bento = bentoml.build(
service="service:MyService",
include=["service.py"],
python={"packages": ["numpy"]},
docker={"python_version": "3.11"},
)
A modern runtime image in service.py:
import bentoml
image = bentoml.images.Image(python_version="3.11").python_packages("numpy")
@bentoml.service(image=image)
class MyService:
pass
Build Context Rules
- Relative paths in
include,exclude,requirements_txt,environment_yml,setup_script,dockerfile_template, wheels, and descriptions usingfile:are resolved relative to the build context. - If
includeis absent, BentoML includes all files under the build context, then appliesexclude,.bentoignore, and built-in ignores such as.git/, virtualenvs,__pycache__/, and.DS_Store. excludealways applies afterinclude; use it to remove secrets, tests, training data, notebooks, and large artifacts.- For
src/layout projects,pyproject.tomlauto-detection can markpython.is_src_layout, and explicitpython: {is_src_layout: true}strips the leadingsrc/when packaging code.
Side-Effect Boundaries
- Static YAML checks and file existence checks are safe.
bentoml buildwrites to the local Bento store and can run package locking; it may access package indexes or local model stores.bentoml build --containerize,bentoml containerize, andbentoml.container.buildrequire an OCI builder and may pull or build images.bentoml push,bentoml pull, andbentoml deployare cloud/network operations and belong in cloud/deployment workflows.