# docker/model-runner architecture

> Architecture diagram of the GitHub repository docker/model-runner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/docker/model-runner
- Repository: https://github.com/docker/model-runner

## Overview

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: [`pkg/server`](https://github.com/docker/model-runner/tree/main/pkg/server) (Server core), [`cmd/cli`](https://github.com/docker/model-runner/tree/main/cmd/cli) (Docker CLI), [`pkg/distribution`](https://github.com/docker/model-runner/tree/main/pkg/distribution) (Distribution core), [`pkg/inference`](https://github.com/docker/model-runner/tree/main/pkg/inference) (Inference core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_control["Control plane"]
  node_cmd_cli["Docker CLI<br/>plugin"]
  node_cli_context[("Context store<br/>CLI state")]
  node_cli_gpu["GPU detect<br/>platform probe"]
  node_model_cli["Rust client<br/>API client"]
  node_dmr["dmr wrapper<br/>launcher<br/>[main.go]"]
end

subgraph group_grp_server["Server plane"]
  node_main_go["Server main<br/>Go entrypoint<br/>[main.go]"]
  node_pkg_server["Server core<br/>Go server"]
  node_pkg_routing["Routing"]
  node_pkg_responses["Responses<br/>API transform"]
  node_pkg_ollama["Ollama API<br/>compat API"]
  node_pkg_anthropic["Anthropic API<br/>provider handler"]
  node_pkg_metrics["Metrics<br/>telemetry"]
  node_pkg_logs["Logs<br/>log API"]
end

subgraph group_grp_dist["Distribution"]
  node_pkg_distribution["Distribution core<br/>model packaging"]
  node_store_layer[("Model store<br/>local state")]
  node_hf_oci["Sources<br/>registry clients"]
end

subgraph group_grp_infer["Inference"]
  node_pkg_inference["Inference core<br/>orchestration"]
  node_sched_layer["Scheduler<br/>serve planner"]
  node_backend_layer["Backends<br/>runtime adapters"]
  node_llama_backend["llama.cpp<br/>default backend"]
  node_other_backends["Alt runtimes<br/>runtime backends"]
end

subgraph group_grp_deploy["Deployment"]
  node_charts["Helm chart<br/>deployment"]
  node_llama_native["Native runtime<br/>C/C++ build"]
end

node_main_go -->|"starts"| node_pkg_server
node_pkg_server -->|"dispatches"| node_pkg_routing
node_pkg_server -->|"serves"| node_pkg_responses
node_pkg_server -->|"serves"| node_pkg_ollama
node_pkg_server -->|"serves"| node_pkg_anthropic
node_pkg_server -->|"exports"| node_pkg_metrics
node_pkg_server -->|"streams"| node_pkg_logs
node_pkg_server -->|"orchestrates"| node_pkg_inference
node_pkg_inference -->|"plans"| node_sched_layer
node_sched_layer -->|"selects"| node_backend_layer
node_backend_layer -->|"includes"| node_llama_backend
node_backend_layer -->|"includes"| node_other_backends
node_llama_backend -->|"depends on"| node_llama_native
node_cmd_cli -->|"stores"| node_cli_context
node_cmd_cli -->|"probes"| node_cli_gpu
node_cmd_cli -->|"drives"| node_pkg_server
node_model_cli -->|"calls"| node_pkg_server
node_dmr -->|"launches"| node_pkg_server
node_dmr -->|"invokes"| node_cmd_cli
node_pkg_distribution -->|"writes"| node_store_layer
node_pkg_distribution -->|"fetches"| node_hf_oci
node_pkg_inference -->|"loads"| node_pkg_distribution
node_charts -->|"deploys"| node_pkg_server
node_charts -->|"mounts"| node_pkg_distribution

click node_main_go "https://github.com/docker/model-runner/blob/main/main.go"
click node_pkg_server "https://github.com/docker/model-runner/tree/main/pkg/server"
click node_pkg_routing "https://github.com/docker/model-runner/tree/main/pkg/routing"
click node_pkg_responses "https://github.com/docker/model-runner/tree/main/pkg/responses"
click node_pkg_ollama "https://github.com/docker/model-runner/tree/main/pkg/ollama"
click node_pkg_anthropic "https://github.com/docker/model-runner/tree/main/pkg/anthropic"
click node_pkg_metrics "https://github.com/docker/model-runner/tree/main/pkg/metrics"
click node_pkg_logs "https://github.com/docker/model-runner/tree/main/pkg/logs"
click node_pkg_inference "https://github.com/docker/model-runner/tree/main/pkg/inference"
click node_sched_layer "https://github.com/docker/model-runner/tree/main/pkg/inference/scheduling"
click node_backend_layer "https://github.com/docker/model-runner/tree/main/pkg/inference/backends"
click node_llama_backend "https://github.com/docker/model-runner/tree/main/pkg/inference/backends/llamacpp"
click node_other_backends "https://github.com/docker/model-runner/tree/main/pkg/inference/backends/vllm"
click node_pkg_distribution "https://github.com/docker/model-runner/tree/main/pkg/distribution"
click node_store_layer "https://github.com/docker/model-runner/tree/main/pkg/distribution/internal/store"
click node_hf_oci "https://github.com/docker/model-runner/tree/main/pkg/distribution/huggingface"
click node_cmd_cli "https://github.com/docker/model-runner/tree/main/cmd/cli"
click node_cli_context "https://github.com/docker/model-runner/tree/main/cmd/cli/pkg/modelctx"
click node_cli_gpu "https://github.com/docker/model-runner/tree/main/cmd/cli/pkg/gpu"
click node_model_cli "https://github.com/docker/model-runner/tree/main/model-cli"
click node_dmr "https://github.com/docker/model-runner/blob/main/cmd/dmr/main.go"
click node_charts "https://github.com/docker/model-runner/tree/main/charts/docker-model-runner"
click node_llama_native "https://github.com/docker/model-runner/tree/main/llamacpp/native"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cmd_cli,node_cli_context,node_cli_gpu,node_model_cli,node_dmr toneBlue
class node_main_go,node_pkg_server,node_pkg_routing,node_pkg_responses,node_pkg_ollama,node_pkg_anthropic,node_pkg_metrics,node_pkg_logs toneAmber
class node_pkg_distribution,node_store_layer,node_hf_oci toneMint
class node_pkg_inference,node_sched_layer,node_backend_layer,node_llama_backend,node_other_backends toneRose
class node_charts,node_llama_native toneIndigo
```

## Components

### Control plane

CLI and client entry points used to manage models and drive the runner.

- [Docker CLI](https://github.com/docker/model-runner/tree/main/cmd/cli): plugin · `docker model ...` control-plane commands for lifecycle, search, and inspection. · `cmd/cli`
- [Context store](https://github.com/docker/model-runner/tree/main/cmd/cli/pkg/modelctx): CLI state · Local CLI context and engine selection state. · `cmd/cli/pkg/modelctx`
- [GPU detect](https://github.com/docker/model-runner/tree/main/cmd/cli/pkg/gpu): platform probe · CLI-side GPU discovery and environment probing. · `cmd/cli/pkg/gpu`
- [Rust client](https://github.com/docker/model-runner/tree/main/model-cli): API client · Standalone Rust client with provider routers for service interaction. · `model-cli`
- [dmr wrapper](https://github.com/docker/model-runner/blob/main/cmd/dmr/main.go): launcher · 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](https://github.com/docker/model-runner/blob/main/main.go): Go entrypoint · Repository-root process that starts the model server. · `main.go`
- [Server core](https://github.com/docker/model-runner/tree/main/pkg/server): Go server · Top-level server lifecycle and wiring for HTTP APIs and backends. · `pkg/server`
- [Routing](https://github.com/docker/model-runner/tree/main/pkg/routing): HTTP routing · Backend routing, service selection, and request dispatch boundaries. · `pkg/routing`
- [Responses](https://github.com/docker/model-runner/tree/main/pkg/responses): API transform · OpenAI-compatible response handling, streaming, and output store. · `pkg/responses`
- [Ollama API](https://github.com/docker/model-runner/tree/main/pkg/ollama): compat API · Ollama-compatible HTTP surface served by the runner. · `pkg/ollama`
- [Anthropic API](https://github.com/docker/model-runner/tree/main/pkg/anthropic): provider handler · Provider-specific handler layer for Anthropic-style requests. · `pkg/anthropic`
- [Metrics](https://github.com/docker/model-runner/tree/main/pkg/metrics): telemetry · Prometheus-style metrics and API usage recording. · `pkg/metrics`
- [Logs](https://github.com/docker/model-runner/tree/main/pkg/logs): log API · Log tailing, merging, and HTTP access to runtime logs. · `pkg/logs`

### Distribution

Model acquisition, packaging, and local store management.

- [Distribution core](https://github.com/docker/model-runner/tree/main/pkg/distribution): model packaging · Pulling, bundling, normalizing, and moving model artifacts. · `pkg/distribution`
- [Model store](https://github.com/docker/model-runner/tree/main/pkg/distribution/internal/store): local state · Persistent bundle, blob, manifest, and index storage layout. · `pkg/distribution/internal/store`
- [Sources](https://github.com/docker/model-runner/tree/main/pkg/distribution/huggingface): registry clients · Hugging Face, OCI, registry, and tarball acquisition paths. · `pkg/distribution/huggingface`

### Inference

Scheduling and backend selection for model execution.

- [Inference core](https://github.com/docker/model-runner/tree/main/pkg/inference): orchestration · Scheduling, loader, runtime flags, and backend selection for serving requests. · `pkg/inference`
- [Scheduler](https://github.com/docker/model-runner/tree/main/pkg/inference/scheduling): serve planner · Chooses how a request is launched, loaded, and executed. · `pkg/inference/scheduling`
- [Backends](https://github.com/docker/model-runner/tree/main/pkg/inference/backends): runtime adapters · Shared backend abstraction plus concrete runtime adapters. · `pkg/inference/backends`
- [llama.cpp](https://github.com/docker/model-runner/tree/main/pkg/inference/backends/llamacpp): default backend · Primary Linux execution path and native runtime integration. · `pkg/inference/backends/llamacpp`
- [Alt runtimes](https://github.com/docker/model-runner/tree/main/pkg/inference/backends/vllm): runtime backends · vLLM, SGLang, diffusers, and MLX execution adapters. · `pkg/inference/backends/vllm`

### Deployment

Container, desktop, and Kubernetes packaging for the runner.

- [Helm chart](https://github.com/docker/model-runner/tree/main/charts/docker-model-runner): deployment · Kubernetes manifests and chart packaging for model-runner deployment. · `charts/docker-model-runner`
- [Native runtime](https://github.com/docker/model-runner/tree/main/llamacpp/native): C/C++ build · Vendored llama.cpp native build and GPU-specific Dockerfiles. · `llamacpp/native`

## Connections

- 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.
