Docker Model Runner Tutorial: Run Local LLMs
Learn how to run local LLMs with Docker Model Runner and Docker Compose, connect your app, and troubleshoot common errors.
On this page
This Docker Model Runner tutorial takes one local language model from a terminal prompt to an OpenAI-compatible API call inside Docker Compose. You’ll run SmolLM2, confirm the host API with curl, and build a Python container that gets its model URL and name from Compose.
Use this setup to test an application’s request format, response handling, and timeouts with local inference. Start each check from the directory and shell shown in the instructions. The command examples use a POSIX shell, such as Bash or Zsh.
Run a local LLM with Docker Model Runner
- 1
Check platform and Compose support
Check that your Docker installation can talk to the daemon, that the Model Runner plugin responds, and that Compose recognizes model bindings. Those checks isolate three different parts of the setup before you download a model.
- macOS with Docker Desktop. Use an Apple Silicon Mac. Open Settings, choose AI, and enable Docker Model Runner. Turn on host-side TCP for the curl and host Python examples, using port
12434in this guide. - Windows with Docker Desktop. Check Docker’s requirements for your Windows architecture, GPU, and driver. Enable the runner in Settings → AI and turn on host-side TCP. Use a POSIX shell for the snippets and run the host HTTP check from the shell where you’ll run Python.
- Linux with Docker Engine. Install Docker’s
docker-model-pluginfrom its package repository for your distribution. Engine enables TCP on port12434by default. Docker documents CPU and supported GPU backends on Linux.
For the Compose example, use Compose v2.38.1 or newer on an installation that supports the
modelsattribute. Python 3 and curl are needed on your host for the optional comparison between host and container calls. See the Docker Model Runner platform requirements and Docker’s setup guide.bashdocker version docker compose version docker model version docker model statusLook for a server section in
docker versionand a running status indocker model status. If the server is missing, start Desktop or the Engine daemon. If the daemon is reachable but the model subcommand is missing, update Desktop or install the Engine plugin before continuing.Check which Docker context you’re using if you work with multiple daemons. A remote context can make Docker commands succeed while curl against your laptop hits a completely different machine. For the walkthrough, use a runner on the machine from which you’ll make the host API request.

In Docker Desktop, enable Model Runner and host-side TCP to follow the local HTTP examples. - macOS with Docker Desktop. Use an Apple Silicon Mac. Open Settings, choose AI, and enable Docker Model Runner. Turn on host-side TCP for the curl and host Python examples, using port
- 2
Download and run SmolLM2
Pull the small, quantized SmolLM2 variant below and run a one-shot prompt. Use the same namespace and tag in curl, Python, and Compose so every check targets the same model.
bashdocker model pull ai/smollm2:360M-Q4_K_M docker model list docker model run ai/smollm2:360M-Q4_K_M 'Explain HTTP caching in one sentence.'The list command should show SmolLM2 among your local models. The run command should print generated text. Wording can vary, so check that the model returns a response before judging its answer.
Start with a short prompt because you’re testing whether the engine can load and generate. Once that works, try a task your application actually performs. Keep a few representative inputs so you can rerun them if you change the model or its configuration.
The model download occupies disk space. Generation also needs working memory for the model, the prompt, and the output it’s producing. A small quantized model gives you room to identify which parts of your setup are slow before you try a larger one.
If you swap models, record the full reference and read the model card and license for that variant. A model selected for a smoke test may need different permissions or capabilities when it becomes part of a commercial app. See the SmolLM2 model listing.
- 3
Call the Model Runner API from your host
List models through the host HTTP endpoint, then send a chat completion and read the generated text. With host TCP enabled on the default port, use
http://localhost:12434/engines/v1as the OpenAI-compatible base URL.bashcurl -fsS http://localhost:12434/engines/v1/models curl -sS http://localhost:12434/engines/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{ "model": "ai/smollm2:360M-Q4_K_M", "messages": [ {"role": "user", "content": "Explain HTTP caching in one sentence."} ], "max_tokens": 80, "stream": false }'The model list establishes that an HTTP request can travel from your host to the runner. The completion also exercises model lookup and generation. Look for the reply in
choices[0].message.contentor read the returned JSON error if the server reports a failure.This curl request sends a JSON content type and omits the authorization header. The OpenAI Python SDK expects an API key setting, so this script supplies the literal string
localas a placeholder. Docker ignores it for the local endpoint. Keep the full base URL explicit so the client sends the prompt to the runner. See Docker’s API reference.Create a new directory for the demo and save the Python file there. If this is your first time isolating Python dependencies, see the guide to Python environments and dependency management with uv.
bashmkdir model-runner-demo cd model-runner-demo python3 -m venv .venv .venv/bin/python -m pip install openaipython — app.pyimport os from openai import OpenAI base_url = os.environ["MODEL_URL"].rstrip("/") model = os.environ["MODEL_NAME"] client = OpenAI( base_url=base_url, api_key="local", timeout=60.0, max_retries=0, ) response = client.chat.completions.create( model=model, messages=[ {"role": "user", "content": "Explain HTTP caching in one sentence."}, ], max_tokens=80, ) print(response.choices[0].message.content)bashMODEL_URL=http://localhost:12434/engines/v1 \ MODEL_NAME=ai/smollm2:360M-Q4_K_M \ .venv/bin/python app.pySet
MODEL_URLto the API root. The SDK appendschat/completionswhen you call the chat method, so supplying the full chat route would produce the wrong path. With the environment variables present, the script can run from the host or inside Compose.The script bounds each response to 80 output tokens and disables SDK retries so the first problem shows up directly in the terminal. If you’re integrating the response into an HTTP service, the REST API guide for Hono illustrates where to validate inputs and return structured errors.
- 4
Connect the Python app with Docker Compose
Add a Dockerfile and a Compose file next to
app.py. Compose binds the application service to the declared model and supplies the API base URL and the model identifier when it creates the container.dockerfile — DockerfileFROM python:3.12-slim WORKDIR /app RUN python -m pip install openai COPY app.py . CMD ["python", "app.py"]text — .dockerignore.venv/ __pycache__/ .git/yaml — compose.yamlservices: app: build: . models: assistant: endpoint_var: MODEL_URL model_var: MODEL_NAME models: assistant: model: ai/smollm2:360M-Q4_K_MRead the top-level
assistantentry as the model definition and the service’sassistantentry as a reference to it.endpoint_varandmodel_varchoose the variable names. The runner integration provides their values.Build the project and start the service. The first build downloads the Python base image and SDK dependencies. If the model is missing from the runner’s cache, Compose provisions it as part of starting the project. See Docker’s Compose model binding guide.
bashdocker compose config docker compose build app docker compose up appThe app prints one response and should exit with code 0. An exited container is expected because
app.pyhandles one prompt and terminates. Usedocker compose logs appto read the answer again anddocker compose ps -ato check the final service state.The demo needs no published ports on the application service. Its only network action is an outbound call to the runner’s endpoint. Compare the container flow below with the earlier host curl call before choosing which address to debug.

Compose supplies the model configuration. The app calls the runner, and the runner loads SmolLM2 to generate the response. Run
docker compose downwhen you’re finished. That removes the demo’s Compose containers and network. The runner can reuse its downloaded model independently of the demo.Keep the model binding visible in code review when you move the demo into a larger Compose project. If you run your services under another container runtime, check how that runtime supplies the endpoint before copying the file. See the Docker Compose to Podman Quadlet migration guide for the container configuration differences.
Troubleshoot Docker Model Runner
Start with the earliest check that fails. A missing command, a refused TCP connection, and an HTTP model lookup error happen at different layers. Fix the first failure before changing the SDK or editing the Compose file.
| Symptom | First check |
|---|---|
| Docker does not recognize `model` | Confirm platform support, then check the Desktop version or Engine plugin. |
| Compose rejects `models` | Check the Compose version and whether the service and top-level entries are correctly indented. |
| Host curl reports connection refused | Check Model Runner status, the host TCP setting, and the configured port. |
| Host works but the app cannot connect | Check whether Compose injected a reachable `MODEL_URL` into the app service. |
| The API reports that the model is missing | Compare the full requested identifier with `docker model list` or the API model list. |
| Generation takes too long or runs out of memory | Retry a single short request with the small model and inspect runner logs. |
Fix a refused connection on the host or in a container
If the Docker Model Runner API returns connection refused from host curl, start with docker model status. If the runner is up, verify the host TCP toggle and port in Docker Desktop. If your port is different, use that value in both the curl URL and the host Python command.
From inside a container, localhost resolves to the container itself. Leave the Compose-injected MODEL_URL in place for the demo. An environment: entry that pins the same variable to your host URL can hide the address you meant to use.
If you configure an app without Compose model bindings, Docker Desktop exposes the runner to containers at http://model-runner.docker.internal/engines/v1. Docker Engine networking works differently and can require an explicit host gateway mapping and port. Follow the Engine tab in Docker’s base URL documentation.
If the server responds with HTTP 404 after you fix connectivity, compare the failing path with /engines/v1/models or /engines/v1/chat/completions. A duplicated /v1 or full completion path passed to the SDK can also produce a 404. Read the error body before deciding to re-pull a model.
Resolve model not found errors
Copy the complete identifier from the runner’s listing, including the namespace and the selected tag. Use the identifier in the HTTP request body and the top-level Compose model. The name assistant is local to the Compose file.
If the name is correct but the result looks wrong, check which runner the request reached. A host command can list models from one Docker context while an environment variable points the application at a different runner. Check both locations before downloading another copy.
Reduce slow generation and memory pressure
Time two identical short requests back to back. The first can include model load time, while the second is more likely to use an already loaded engine. Check docker model logs for backend errors and verify which acceleration backend your hardware supports.
Track three knobs separately. Output length limits generated tokens. Context size caps the input and output history the model can work with. Concurrency controls how many requests compete for resources. For a development machine, start with small values and raise one at a time.
If the runner still struggles, stop other resource-heavy workloads and retest with a short prompt. Record latency along with model tag, machine, and prompt size. That gives your teammates enough context to distinguish a model regression from a slower device.
Prepare a local inference integration for production
Keep the runner on a trusted network. The local endpoint accepts requests from clients that can reach it, including clients that send the placeholder API key from this tutorial. For shared access, put an authenticated application or gateway in front and restrict direct access to the runner.
Capture representative latency and memory measurements on deployment hardware. Include cold requests, warm requests, and the busiest traffic you expect. Use those observations to set timeouts, input limits, and a concurrency limit.
Separate HTTP reachability from inference readiness. A model list response shows the API is answering. A small completion exercises model loading and generation. Pick a health check that reflects what traffic your application can serve without sending a full prompt for every probe.
Treat generated text as application input. Validate it against the contract you expect before storing structured values, rendering HTML, or invoking other services. Log timing, model names, and failure categories so you can diagnose errors without recording prompt text by default.
Frequently Asked Questions
Can you use Docker Model Runner without an API key?
Yes. Send a request directly to the local runner with curl and omit the authorization header. If you use the OpenAI SDK, configure the local base URL and a placeholder key such as local to satisfy the SDK.
Limit who can reach that local endpoint. The placeholder has no role in access control, so anyone on a reachable network can use the runner unless a separate control blocks access.
If a project supports local and hosted inference, give each mode its own explicit base URL and credential configuration. This makes a provider switch visible in review and keeps the local example independent of a developer’s shell credentials.
Can Docker Model Runner run without a dedicated GPU?
Docker Engine on Linux supports CPU inference for compatible models. Start with a small quantized model, a short context, and one request at a time to keep memory use and waiting time manageable.
Docker Desktop support has platform-specific hardware requirements, including Apple Silicon on macOS. Check the platform requirements before assuming a setup that runs on Linux will work on your laptop.
If your deployment target is CPU-only, test there early using the same model tag and a representative prompt. A laptop with acceleration can hide how long the first response takes on the target hardware.
How does Docker Compose supply the model URL and name?
- Declare the artifact. The top-level
modelsmapping names the model dependency and identifies the artifact. - Bind the service. The service’s
modelsmapping points to that definition and names the environment variables. - Read the values. The runner integration supplies the connection details when Compose creates the application container.
How do you check which models the Docker Model Runner API can see?
Call the OpenAI-compatible models route from the host. Use the port enabled in your runner configuration. The JSON response contains the model identifiers available through that endpoint.
curl -fsS http://localhost:12434/engines/v1/modelsCan Docker Model Runner generate responses offline?
Generation can run locally once the model and inference engine are available locally. Download the model, Python dependencies, and container base image before you go offline, then verify the entire setup in the environment where it will run.
The wider application may still call remote services, and Docker’s documented usage data behavior depends on the installation. Review its privacy and data collection details if outbound traffic matters to your environment.
For a reliable offline check, make the first successful run while connected, then run the same prompt with network access disabled. If that second run fails, identify which dependency the startup sequence still needs.
Does docker compose down remove the downloaded model?
Compose down removes the project’s service containers and networks. A model pulled into the runner’s local cache can be present after the project stops, so it may still take up disk space.
List models with docker model list. Once you confirm other apps no longer use the demo variant, remove that particular model with the command below.
docker model rm ai/smollm2:360M-Q4_K_MRelated Articles
Docker Compose to Podman Quadlet: A Practical Migration Guide
Convert a docker-compose.yml to Podman Quadlet files step by step, with a full example, rootless setup, and the daemon-reload gotchas that trip people up.
How to Switch to uv: Replace pip, virtualenv, and Poetry in Your Python Project
uv replaces pip, virtualenv, and Poetry with a single fast binary. Step-by-step guide to migrating your existing Python project and setting up GitHub Actions CI.
Hono.js Tutorial: REST API with Zod, JWT & Cloudflare Workers
Step-by-step Hono.js tutorial: routing, middleware, Zod validation, JWT auth, and deployment to Cloudflare Workers and Node.js. Working code throughout.