Skip to content

Host Model Access

A language model can run on your machine, outside Docker, in a server such as Ollama, LM Studio or llama.cpp's server. The services of the stack that run your code or call a model reach that server at host.docker.internal, and read its address from LLM_BASE_URL. The model server stays on the host because containers on macOS cannot use the Mac's GPU, and GPU access in containers differs by platform. Any server with an OpenAI-compatible API works. The end-to-end tests run the commands below on every release, against a small stand-in server on the runner.

This guide builds on Getting Started.

The airflow, spark, flink, mlflow, langfuse, trino and metabase containers on the odctl network call the model server on the host at LLM_BASE_URL through host.docker.internal; odctl check llm sends GET /models from a short-lived alpine container the same way

Run a Model Server on the Host

Server Address on the host Listens on by default To listen beyond 127.0.0.1
Ollama http://localhost:11434/v1 127.0.0.1:11434 OLLAMA_HOST=0.0.0.0:11434 (FAQ)
LM Studio http://localhost:1234/v1 127.0.0.1 lms server start --bind 0.0.0.0 (CLI)
llama.cpp server http://localhost:<port>/v1 127.0.0.1 --host 0.0.0.0

On Linux, and on Docker Engine inside WSL2, a container reaches the host through Docker's bridge address, so a server that listens only on 127.0.0.1 cannot be reached. Make it listen on 0.0.0.0. Ollama runs as a systemd service on Linux:

docs/snippets/local-models/commands.sh:ollama-linux
1
2
3
4
5
6
sudo systemctl edit ollama.service
# In the editor, add these two lines, then save and exit:
#   [Service]
#   Environment="OLLAMA_HOST=0.0.0.0:11434"
sudo systemctl daemon-reload
sudo systemctl restart ollama

On macOS, Ollama runs as an application:

docs/snippets/local-models/commands.sh:ollama-macos
launchctl setenv OLLAMA_HOST "0.0.0.0:11434"
# Then quit Ollama and start it again.

A server on 0.0.0.0 also accepts connections from your local network. Keep the host's firewall closed to it if that matters on your network.

Set It Up for Your Platform

odctl init writes three keys to .odctl/.env:

  • LLM_BASE_URL is the server's OpenAI-compatible base URL as the containers reach it. It is http://host.docker.internal:11434/v1 by default, Ollama's address.
  • LLM_MODEL is the model the services call when the code does not name one, such as Trino's ai catalog. It is llama3.2 by default; Call the Model from a Container sets it to a model your server has.
  • ODCTL_HOST_GATEWAY is empty by default. Set it to true where Docker does not resolve host.docker.internal by itself. odctl then adds host.docker.internal:host-gateway to the services that call the server, and to no other.
Platform Engine Set ODCTL_HOST_GATEWAY Tested What the vendor's docs say
macOS OrbStack No; true also works Yes, with Ollama on 127.0.0.1 host.docker.internal reaches a server on the Mac (OrbStack)
macOS Docker Desktop No Not tested host.docker.internal resolves to the host (Docker Desktop)
macOS Colima Not known Not tested Colima's FAQ does not say how a container reaches the host
Linux Docker Engine 20.10.0 or later Yes Yes, in the end-to-end tests host-gateway in --add-host maps a name to the host (Docker Engine)
Linux Docker Desktop for Linux No Not tested As Docker Desktop on macOS
WSL2 Docker Desktop No Not tested As Docker Desktop on macOS
WSL2 Docker Engine inside the distribution Yes Not tested As Docker Engine on Linux; Windows is a separate host, as below (WSL networking)

With Docker Engine inside WSL2, host.docker.internal is the WSL2 virtual machine, so it reaches a server that runs inside the distribution. A server on Windows is reached at another address. In WSL2's default NAT mode it is the Windows host's address, which ip route show | grep -i default | awk '{ print $3}' prints inside the distribution (WSL networking); put that address in LLM_BASE_URL, and make the server listen on 0.0.0.0. Langfuse admits a private address only when its host is listed, so for Langfuse also add LANGFUSE_LLM_CONNECTION_WHITELISTED_HOST="host.docker.internal,<that address>" to .odctl/.env (a comma-separated list) and run odctl recreate langfuse.

Turn the flag on:

docs/snippets/local-models/commands.sh:gateway-flag
sed -i.bak 's|^ODCTL_HOST_GATEWAY=.*|ODCTL_HOST_GATEWAY="true"|' .odctl/.env

For a server other than Ollama, change the address, here to LM Studio's port. With Docker Engine inside WSL2 and the server on Windows, keep the Windows address from above in place of host.docker.internal:

docs/snippets/local-models/commands.sh:base-url
sed -i.bak 's|^LLM_BASE_URL=.*|LLM_BASE_URL="http://host.docker.internal:1234/v1"|' .odctl/.env

A change to any of the keys reaches a running service when it is recreated, for example with odctl recreate airflow. A server that needs an API key is not supported.

Check the Connection

odctl check llm starts a short-lived alpine:3.24 container on the odctl network, the way the stack's services run, and requests <LLM_BASE_URL>/models:

docs/snippets/local-models/commands.sh:check
odctl check llm
odctl check llm --json | python3 -c 'import json, sys; print(json.load(sys.stdin)["models"])'

It prints the models the server lists. When the request fails, it names the cause and what to change:

Failure Cause
The host name does not resolve Docker does not resolve host.docker.internal: set ODCTL_HOST_GATEWAY=true. For another name, correct LLM_BASE_URL
The connection failed and LLM_BASE_URL names localhost or 127.0.0.1 In a container that is the container itself: use host.docker.internal
The connection was refused The server is not running, or listens only on 127.0.0.1
No reply within 5 seconds A firewall on the host drops connections from Docker's network
No complete reply within 30 seconds The server keeps sending without finishing the model list, so check the server's own logs
The server answered an HTTP error LLM_BASE_URL has the wrong path; it usually ends in /v1

Call the Model from a Container

These services get LLM_BASE_URL and LLM_MODEL, and the host gateway when the flag is on:

  • airflow;
  • spark-master, where spark-sql and spark-submit run the driver, and the Spark workers;
  • the Flink jobmanager, where the SQL client and job clients run, and the task managers;
  • mlflow and mlflow-serve;
  • langfuse-web and langfuse-worker;
  • trino, for its ai catalog;
  • metabase, for its AI features, which gets LLM_BASE_URL only, because Metabase picks the model in its own settings.

Start Airflow. If it was already running when you changed .env, run odctl recreate airflow instead, so that it gets the new keys:

odctl up airflow

From the airflow container, the server lists its models:

docs/snippets/local-models/commands.sh:container
# The models the server lists, as the airflow container reaches it.
docker exec airflow sh -c 'curl -s "$LLM_BASE_URL/models"'

A task reads the address and the model from the environment and calls the chat API. This function uses only Python's standard library, so it runs in any of those containers that has Python, such as airflow; metabase has no LLM_MODEL:

docs/snippets/local-models/llm_task.py
"""Ask the model server on the host one question, from inside a container.

LLM_BASE_URL and LLM_MODEL are set in every service that runs your code and calls
a model server on the host, so the code reads the address and the model from the
environment. It uses only the standard library, so it runs in any of those
containers that has Python, and it is the body an Airflow task would have.
"""

import json
import os
import urllib.request


def ask(question: str) -> str:
    """Send one chat message to the OpenAI-compatible server and return the reply."""
    request = urllib.request.Request(
        os.environ["LLM_BASE_URL"].rstrip("/") + "/chat/completions",
        data=json.dumps(
            {
                "model": os.environ["LLM_MODEL"],
                "messages": [{"role": "user", "content": question}],
            }
        ).encode(),
        headers={"Content-Type": "application/json"},
    )
    with urllib.request.urlopen(request, timeout=120) as response:
        return json.load(response)["choices"][0]["message"]["content"]


if __name__ == "__main__":
    print(ask("Say hello in five words."))

Make the first model the server lists the default in .env, so that it is set in MODEL and in LLM_MODEL:

docs/snippets/local-models/commands.sh:model
1
2
3
4
# The first model the server lists, made the services' default in .env. A server
# that lists none leaves .env as it is.
MODEL=$(odctl check llm --json | python3 -c 'import json, sys; m = json.load(sys.stdin)["models"]; print(m[0]) if m else sys.exit("The server lists no model: pull one first, such as ollama pull llama3.2")')
[ -n "$MODEL" ] && sed -i.bak "s|^LLM_MODEL=.*|LLM_MODEL=\"$MODEL\"|" .odctl/.env

Save the function as llm_task.py and run it once in the airflow container:

docs/snippets/local-models/commands.sh:task
1
2
3
# Run the task's function once in the airflow container, with that model. The
# running container still has the old LLM_MODEL until it is recreated.
docker exec -i -e LLM_MODEL="$MODEL" airflow python - < llm_task.py

It prints the model's reply. In a DAG, call ask from a task, as Airflow DAGs from S3 shows for any task. Run odctl recreate airflow first, so that the DAG's tasks read the new LLM_MODEL.

Use the Model in Langfuse

Langfuse's Playground and its LLM-as-a-judge evaluations call a model through an LLM connection. Langfuse refuses a connection to a private address unless its host is listed, so the profile lists host.docker.internal in LANGFUSE_LLM_CONNECTION_WHITELISTED_HOST. Start Langfuse, or recreate it if it was running when you changed .env:

odctl up langfuse

Create the connection through Langfuse's public API, with the MODEL set above:

docs/snippets/local-models/commands.sh:langfuse
1
2
3
4
5
6
# Langfuse answers 201 for a new connection and 200 for an update. Its secretKey
# is required; a server that needs no key ignores it.
curl -s -o /dev/null -w '%{http_code}\n' -X PUT -u pk-lf-odctl:sk-lf-odctl \
  -H 'Content-Type: application/json' \
  -d "{\"provider\": \"host\", \"adapter\": \"openai\", \"secretKey\": \"none\", \"baseURL\": \"$(docker exec langfuse-web printenv LLM_BASE_URL)\", \"customModels\": [\"$MODEL\"], \"withDefaultModels\": false}" \
  http://127.0.0.1:3005/api/public/llm-connections

The connection is named host and offers only that model:

Langfuse LLM connections showing the host connection with the OpenAI adapter

Langfuse covers the rest of the profile.

Use the Model in MLflow

MLflow's AI Gateway can route an endpoint to the server on the host. Call a Model on the Host in the MLflow guide creates one.

Use the Model in Trino

Trino's catalog ai, in .odctl/trino/catalog/ai.properties, gives SQL functions such as ai_gen, ai_classify and ai_translate in its ai schema (AI functions). Each call sends a chat request to the server on the host. Trino adds /v1/chat/completions to the catalog's endpoint, so the trino service passes LLM_BASE_URL without its /v1. The catalog reads its model from LLM_MODEL. If Trino is not running, start it with odctl up trino, which reads the new .env; odctl recreate does not start the profiles Trino needs. If it is running, recreate it after the change to .env above:

docs/snippets/local-models/commands.sh:trino-model
# Recreate Trino so that its ai catalog reads LLM_MODEL from .env.
odctl recreate trino

Then call the model from SQL:

docs/snippets/local-models/commands.sh:trino
# Catalogs load a minute or so after Trino starts; until then this fails.
docker exec trino trino --execute "SELECT ai.ai.ai_gen('Say hello in five words.')"

It prints the model's reply. The access rules in .odctl/trino/rules.json let every user run the functions of ai.ai, and no other catalog's functions. Trino and Metabase covers the rest of the profile.

Use the Model in Metabase

The metabase service sets MB_LLM_VLLM_API_BASE_URL to LLM_BASE_URL, so Metabase's admin AI settings list a vLLM connection to the server, with the models it lists. Metabase's vLLM provider works with any OpenAI-compatible server. Metabase refuses an LLM on a private or local address by default, so the service also sets MB_LLM_ALLOWED_NETWORKS=allow-all. Metabot needs a model that calls tools: Metabase's vLLM provider checks for tool calls and for a context window of at least 16,384 tokens, so a small model may not pass. The end-to-end tests check that Metabase lists the server's models; they do not run Metabot.

With qwen3.8:27b-mlx on Ollama, Metabot built a count query on the sample ORDERS table in about two minutes. The query returns 18,760, but the model's reply says 4,000, so read the number from the query result, not from the reply:

Metabot answering a question about the sample database with a count query