How docker/model-runner works
1. What this repository is
Docker Model Runner is a multi-binary system for managing and serving AI models locally or in containers. The core runtime is a Go-based model server, surrounded by a Docker CLI plugin, a standalone Rust client, model distribution tooling, and deployment packaging for Docker Desktop, Docker Engine, and Kubernetes.
2. Primary entry points
The main server lives at the repository root (main.go) and in pkg/server. The Docker CLI plugin is built from cmd/cli, exposed as docker model .... There is also a small convenience wrapper cmd/dmr that starts the server, runs a CLI command against it, then shuts the server down. Separately, model-cli/ is a Rust client that speaks to the same service API.
3. Control plane vs. data plane
The CLI layer is the control plane: it creates contexts, pulls or launches models, inspects status, and manages lifecycle. The server is the data plane: it accepts HTTP requests, selects an inference backend, loads model artifacts, and streams generated responses back to clients.
4. HTTP API surface
The server exposes several API families: a Docker Model Runner REST API for model lifecycle, OpenAI-compatible endpoints under pkg/responses, Ollama-compatible endpoints under pkg/ollama, metrics under pkg/metrics, logs under pkg/logs, and routing/service abstractions under pkg/routing. pkg/anthropic provides a provider-specific handler layer, and the Rust model-cli includes provider routers for OpenAI and Anthropic-style requests.
5. Inference orchestration
pkg/inference is the orchestration layer that decides how a request should be served. It includes scheduling, loader, runner, platform detection, runtime flag handling, and backend selection. This is where the system chooses between supported inference backends such as llama.cpp, vLLM, SGLang, diffusers, and MLX based on model type, platform, and configuration.
6. Backend implementations
Backend-specific code lives under pkg/inference/backends/*. These backends encapsulate the execution model for each runtime, including configuration, startup/download behavior, and platform-specific details. The llama.cpp backend has the strongest integration because it is the default execution path on Linux and is tied to the vendored native runtime under llamacpp/native.
7. Model acquisition and packaging
pkg/distribution is the model artifact subsystem. It handles pulling from registries, normalizing model formats, bundling/unbundling, tarball handling, OCI image interactions, Hugging Face clients, and upload/download flows. This layer converts external model sources into the local store layout expected by the inference backends.
8. Storage and local state
Persistent state is managed through store-oriented packages in pkg/distribution/internal/store, along with CLI-side context storage in cmd/cli/pkg/modelctx. The README’s “models” directory corresponds to the persistent model store mounted into Docker runs. The system also keeps response/streaming state in pkg/responses and tail/log buffering in pkg/tailbuffer.
9. Request transformation and streaming
The response path is not just pass-through. pkg/responses contains request/response handlers, transformation logic, streaming helpers, and a local store for generated outputs. This is the layer that adapts upstream model-backend protocols into stable external APIs such as OpenAI-style chat/completions.
10. Platform and runtime boundaries
The repo includes explicit support for cross-platform behavior: GPU detection in cmd/cli/pkg/gpu, sandboxing in pkg/sandbox, TLS utilities in pkg/tls, environment/config helpers, and Windows/macOS/Linux-specific files throughout the tree. These boundaries matter because backend selection, binary packaging, and model execution differ significantly by OS and GPU stack.
11. Packaging and deployment
The project is packaged as Docker images via the root Dockerfile, CLI-specific Dockerfiles, and cmd/cli/docker-bake.hcl. For Kubernetes, there is a Helm chart and static YAML manifests under charts/docker-model-runner. The README also notes Docker Desktop integration and Docker Engine installation paths, which are the main runtime deployment targets.
12. External systems this architecture depends on
The system integrates with OCI-compliant registries, Docker Hub, Hugging Face, and upstream model runtime images such as ghcr.io/ggml-org/llama.cpp and vLLM release wheels. The server is designed to expose Prometheus-compatible metrics from the backend, and the CLI can also interact with NVIDIA NIM endpoints, which are treated as another model-serving target in the command set.
13. Supporting assets and demos
demos/ contains example end-to-end consumer applications for embeddings, extraction, gateway use, and multimodal workflows. These are not core runtime components, but they show the intended architecture: a client application calls the model runner API, which in turn orchestrates model storage, backend startup, and inference streaming.
14. Build and verification workflow
The repository is organized so the same codebase can produce the server, plugin, wrapper, docs, native llama.cpp artifacts, and container images. CI and e2e tests exercise the API and CLI together, which reflects the architecture’s central assumption: the value of the project comes from the full path from model acquisition to served inference, not from any single binary in isolation.
Main entry points: server Server core · cli Docker CLI · distribution Distribution core · inference Inference core
Components 23
Control plane
CLI and client entry points used to manage models and drive the runner.
- Docker CLI · `docker model ...` control-plane commands for lifecycle, search, and inspection.
cmd/cli - Context store · Local CLI context and engine selection state.
cmd/cli/pkg/modelctx - GPU detect · CLI-side GPU discovery and environment probing.
cmd/cli/pkg/gpu - Rust client · Standalone Rust client with provider routers for service interaction.
model-cli - dmr wrapper · Convenience binary that starts the server, runs a CLI command, then shuts down.
cmd/dmr/main.go
Server plane
HTTP serving, routing, and response transformation inside the model runner.
- Server main · Repository-root process that starts the model server.
main.go - Server core · Top-level server lifecycle and wiring for HTTP APIs and backends.
pkg/server - Routing · Backend routing, service selection, and request dispatch boundaries.
pkg/routing - Responses · OpenAI-compatible response handling, streaming, and output store.
pkg/responses - Ollama API · Ollama-compatible HTTP surface served by the runner.
pkg/ollama - Anthropic API · Provider-specific handler layer for Anthropic-style requests.
pkg/anthropic - Metrics · Prometheus-style metrics and API usage recording.
pkg/metrics - Logs · Log tailing, merging, and HTTP access to runtime logs.
pkg/logs
Distribution
Model acquisition, packaging, and local store management.
- Distribution core · Pulling, bundling, normalizing, and moving model artifacts.
pkg/distribution - Model store · Persistent bundle, blob, manifest, and index storage layout.
pkg/distribution/internal/store - Sources · Hugging Face, OCI, registry, and tarball acquisition paths.
pkg/distribution/huggingface
Inference
Scheduling and backend selection for model execution.
- Inference core · Scheduling, loader, runtime flags, and backend selection for serving requests.
pkg/inference - Scheduler · Chooses how a request is launched, loaded, and executed.
pkg/inference/scheduling - Backends · Shared backend abstraction plus concrete runtime adapters.
pkg/inference/backends - llama.cpp · Primary Linux execution path and native runtime integration.
pkg/inference/backends/llamacpp - Alt runtimes · vLLM, SGLang, diffusers, and MLX execution adapters.
pkg/inference/backends/vllm
Deployment
Container, desktop, and Kubernetes packaging for the runner.
- Helm chart · Kubernetes manifests and chart packaging for model-runner deployment.
charts/docker-model-runner - Native runtime · Vendored llama.cpp native build and GPU-specific Dockerfiles.
llamacpp/native
Connections 24
- Server main → Server core: starts · Root binary boots the server core.
- Server core → Routing: dispatches · Server wires request routing and backend service selection.
- Server core → Responses: serves · Server exposes OpenAI-compatible response APIs.
- Server core → Ollama API: serves · Server exposes Ollama-compatible endpoints.
- Server core → Anthropic API: serves · Server includes provider-specific Anthropic handling.
- Server core → Metrics: exports · Server publishes metrics and usage signals.
- Server core → Logs: streams · Server provides log access and tailing.
- Server core → Inference core: orchestrates · Server delegates inference lifecycle and execution decisions.
- Inference core → Scheduler: plans · Inference core uses scheduling and loading logic.
- Scheduler → Backends: selects · Scheduler chooses among backend implementations.
- Backends → llama.cpp: includes · llama.cpp is the primary backend path.
- Backends → Alt runtimes: includes · Additional adapters cover vLLM, SGLang, diffusers, and MLX.
- llama.cpp → Native runtime: depends on · llama.cpp backend integrates with native build artifacts.
- Docker CLI → Context store: stores · CLI persists active context and engine selection.
- Docker CLI → GPU detect: probes · CLI checks GPU/platform capability before actions.
- Docker CLI → Server core: drives · Plugin calls the local runner to manage models and requests.
- Rust client → Server core: calls · Rust client speaks the same service API.
- dmr wrapper → Server core: launches · Wrapper starts the server process for transient CLI use.
- dmr wrapper → Docker CLI: invokes · Wrapper runs a CLI command against the running server.
- Distribution core → Model store: writes · Distribution normalizes artifacts into the local model store.
- Distribution core → Sources: fetches · Distribution pulls from registries, Hugging Face, OCI, and tarballs.
- Inference core → Distribution core: loads · Inference loads model artifacts prepared by distribution.
- Helm chart → Server core: deploys · Helm and manifests package the server for Kubernetes.
- Helm chart → Distribution core: mounts · Deployment expects the persistent model store layout.