Implementation:Bentoml BentoML Docker Backend
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Container, OCI |
| Last Updated | 2026-02-13 15:00 GMT |
Overview
Implements the standard Docker container builder backend for BentoML, extending the OCIBuilder base class to build OCI images using the docker build command with BuildKit support.
Description
The docker module provides the standard Docker backend implementation for BentoML's container build system. It extends the OCIBuilder base class and exports the standard backend interface:
- BUILDKIT_SUPPORT -- Set to True since Docker 18.09+ supports BuildKit.
- ENV -- Default environment variables: DOCKER_BUILDKIT=1 (enable BuildKit) and DOCKER_SCAN_SUGGEST=false (suppress scan suggestions).
- find_binary() -- Locates the docker executable using shutil.which. This function is also reused by the Buildx backend.
- health() -- Verifies Docker is installed, then checks the server version (parsed via regex) to ensure it is >= 18.09 for BuildKit compatibility. Respects the DOCKER_BUILDKIT environment variable.
- construct_build_args() -- Builds the CLI argument list for docker build. Supports the following options:
- add_host -- Host-to-IP mappings (dict or tuple)
- build_arg -- Build-time variables (dict or tuple)
- cache_from -- Cache source specification (string or dict)
- isolation -- Windows container isolation mode (default/process/hyperv); warns on non-Windows
- label -- Image labels (dict or tuple)
- output -- Custom output configuration (string or dict)
- secret -- Build secrets (string or dict)
- Additional keyword arguments are passed through with underscores replaced by hyphens.
Usage
Use this backend as the default container builder for building Docker images with BentoML's containerization workflow.
Code Reference
Source Location
- Repository: Bentoml_BentoML
- File: src/bentoml/_internal/container/docker.py
- Lines: 1-106
Signature
BUILDKIT_SUPPORT = True
ENV = {"DOCKER_BUILDKIT": "1", "DOCKER_SCAN_SUGGEST": "false"}
def find_binary() -> str | None: ...
def health() -> bool: ...
def construct_build_args(
*,
context_path: PathType = ".",
add_host: dict[str, str] | ArgType = None,
build_arg: dict[str, str] | ArgType = None,
cache_from: str | dict[str, str] | ArgType = None,
isolation: t.Literal["default", "process", "hyperv"] | None = None,
label: dict[str, str] | ArgType = None,
output: str | dict[str, str] | ArgType = None,
secret: str | dict[str, str] | ArgType = None,
**kwargs: t.Any,
) -> Arguments: ...
Import
from bentoml._internal.container import docker
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| context_path | PathType | No | Build context directory (default: ".") |
| add_host | dict or tuple | No | Extra host-to-IP mappings |
| build_arg | dict or tuple | No | Build-time variables |
| cache_from | str or dict | No | Cache source specification |
| isolation | Literal["default","process","hyperv"] | No | Windows container isolation mode |
| label | dict or tuple | No | Image labels |
| output | str or dict | No | Output configuration |
| secret | str or dict | No | Build secrets |
Outputs
| Name | Type | Description |
|---|---|---|
| Arguments | Arguments | Constructed CLI argument list for docker build command |
| bool | bool | Health check result |
| str or None | str or None | Path to docker binary (from find_binary) |
Usage Examples
from bentoml._internal.container import docker
# Check if docker is available and healthy
if docker.health():
# Construct build arguments
args = docker.construct_build_args(
context_path="/path/to/project",
build_arg={"VERSION": "1.0", "ENV": "production"},
label={"maintainer": "team@example.com"},
cache_from="myrepo/cache:latest",
tag=("myimage:latest",),
)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment