Dev Encyclopedia
ArticlesToolsContactAbout

Get notified when new content drops

No spam. Just new articles, tools, and updates straight to your inbox.

Dev Encyclopedia

A reference for builders

Dev.to
Discord
WhatsApp Channel
daily.dev
Hashnode
X

Content

  • Articles
  • Tools
  • About
  • Contact

Connect

  • support@devencyclopedia.com
  • RSS Feed

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

© 2026 Dev Encyclopedia

Back to top ↑
  1. Home
  2. /Blog
  3. /Docker Model Runner Tutorial: Run Local LLMs
devops13 min read

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.

Zeeshan Tofiq
Zeeshan Tofiq
December 5, 2026
On this page

On this page

  • Run a local LLM with Docker Model Runner
  • Check platform and Compose support
  • Download and run SmolLM2
  • Call the Model Runner API from your host
  • Connect the Python app with Docker Compose
  • Troubleshoot Docker Model Runner
  • Fix a refused connection on the host or in a container
  • Model not found
  • Slow generation or memory pressure
  • Prepare a local inference integration for production
  • Frequently Asked Questions

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.

💡 Quick test for an enabled runner

Run docker model run ai/smollm2:360M-Q4_K_M 'Say hello in one sentence.' to check whether the runner can download and serve the model. The first download and load can take longer than later requests.

Run a local LLM with Docker Model Runner

  1. 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 12434 in 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-plugin from its package repository for your distribution. Engine enables TCP on port 12434 by 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 models attribute. 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.

    bash
    docker version
    docker compose version
    docker model version
    docker model status

    Look for a server section in docker version and a running status in docker 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.

    Docker Desktop AI settings with Model Runner and host-side TCP enabled on port 12434
    In Docker Desktop, enable Model Runner and host-side TCP to follow the local HTTP examples.
  2. 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.

    bash
    docker 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. 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/v1 as the OpenAI-compatible base URL.

    bash
    curl -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.content or 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 local as 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.

    bash
    mkdir model-runner-demo
    cd model-runner-demo
    python3 -m venv .venv
    .venv/bin/python -m pip install openai
    python — app.py
    import 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)
    bash
    MODEL_URL=http://localhost:12434/engines/v1 \
    MODEL_NAME=ai/smollm2:360M-Q4_K_M \
    .venv/bin/python app.py

    Set MODEL_URL to the API root. The SDK appends chat/completions when 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. 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 — Dockerfile
    FROM 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.yaml
    services:
      app:
        build: .
        models:
          assistant:
            endpoint_var: MODEL_URL
            model_var: MODEL_NAME
    
    models:
      assistant:
        model: ai/smollm2:360M-Q4_K_M

    Read the top-level assistant entry as the model definition and the service’s assistant entry as a reference to it. endpoint_var and model_var choose 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.

    bash
    docker compose config
    docker compose build app
    docker compose up app

    The app prints one response and should exit with code 0. An exited container is expected because app.py handles one prompt and terminates. Use docker compose logs app to read the answer again and docker compose ps -a to 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 provides MODEL_URL and MODEL_NAME to the Python container, which sends a chat request to Docker Model Runner and SmolLM2
    Compose supplies the model configuration. The app calls the runner, and the runner loads SmolLM2 to generate the response.

    Run docker compose down when 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.

SymptomFirst 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 refusedCheck Model Runner status, the host TCP setting, and the configured port.
Host works but the app cannot connectCheck whether Compose injected a reachable `MODEL_URL` into the app service.
The API reports that the model is missingCompare the full requested identifier with `docker model list` or the API model list.
Generation takes too long or runs out of memoryRetry 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?
  1. Declare the artifact. The top-level models mapping names the model dependency and identifies the artifact.
  2. Bind the service. The service’s models mapping points to that definition and names the environment variables.
  3. Read the values. The runner integration supplies the connection details when Compose creates the application container.

💡 Tip

Keep the same variable names when you change the model reference. For example, update the artifact under assistant and recreate the app service so the container gets the new identifier without a change to its Python code.

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.

bash
curl -fsS http://localhost:12434/engines/v1/models

💡 Tip

When diagnosing a container, probe the API base URL supplied to that service. A successful host call gives you a TCP baseline for comparison. Check the returned IDs before opening the SDK configuration. If the endpoint answers but the expected ID is missing from the response, follow the model lookup checks for that runner.

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

bash
docker model rm ai/smollm2:360M-Q4_K_M

💡 Tip

If you plan to repeat the tutorial offline, keep the model cached. Removing it saves disk space, but the next run that needs this exact tag will need access to the model artifact again.

Written by

Zeeshan Tofiq, Full Stack Developer
Zeeshan Tofiq

Full Stack Developer

Full stack developer with over 6 years of experience building production applications. Writes practical guides on JavaScript, TypeScript, React, Node.js, and cloud infrastructure. Focused on helping developers solve real problems with clean, maintainable code.

All articles by Zeeshan TofiqGitHubLinkedIn

Enjoyed this article?

Get practical dev guides, tool updates, and new articles delivered straight to your inbox. No spam, unsubscribe anytime.

Related Articles

devops

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.

Jul 15, 2026·32 min read
python

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.

Jun 4, 2026·25 min read
backend

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.

Jun 15, 2026·14 min read

On this page

  • Run a local LLM with Docker Model Runner
  • Check platform and Compose support
  • Download and run SmolLM2
  • Call the Model Runner API from your host
  • Connect the Python app with Docker Compose
  • Troubleshoot Docker Model Runner
  • Fix a refused connection on the host or in a container
  • Model not found
  • Slow generation or memory pressure
  • Prepare a local inference integration for production
  • Frequently Asked Questions