Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Docker: mount the host's LM Studio, Ollama and Hermes models into the container (#10936)

Nilaye1205f50e359
diff --git a/docker/run.sh b/docker/run.sh
index 08097ce9d45..3f0d8dfad8e 100755
--- a/docker/run.sh
+++ b/docker/run.sh
@@ -5,7 +5,8 @@
# --ipc=host ample /dev/shm; the default 64MB crashes DataLoader workers
# --ulimit memlock=-1 unlimited pinned memory (else multi-GPU training stalls)
# --ulimit stack=64MB larger libtorch thread stack (some kernels OOM the 8MB default)
-# Plus mounts the host HF + Triton caches so downloads and kernels persist.
+# Plus mounts the host HF + Triton caches so downloads and kernels persist, and the
+# LM Studio, Ollama and Hermes model folders it finds, read-only, so Studio lists them.
#
# With no command the image's own CMD runs, which on unsloth/unsloth:latest is the
# Studio (8000) + JupyterLab (8888) launcher, not a REPL. $PWD is at /workspace/host.
@@ -34,6 +35,10 @@
# HF_HOME=$HOME/.cache/huggingface host HF cache dir to mount
# TRITON_CACHE_DIR=...unsloth-triton host Triton cache dir to mount
# UNSLOTH_WORKDIR=$PWD host dir mounted at /workspace/host
+# UNSLOTH_LMSTUDIO_DIR=<detected> host LM Studio models dir, "none" to skip
+# UNSLOTH_OLLAMA_DIR=<detected> host Ollama models dir, "none" to skip
+# UNSLOTH_HERMES_DIR=<detected> host Hermes models dir, "none" to skip
+# UNSLOTH_MODELS_DIR= host dir of GGUFs/model folders for Studio
# UNSLOTH_STUDIO_VOLUME=unsloth-studio named volume for Studio's data (accounts,
# chats, outputs) at /opt/unsloth-studio;
# set it empty to run without one
@@ -128,6 +133,77 @@ fi
mkdir -p "$HF_CACHE" "$TRITON_CACHE"
+first_dir() {
+ local dir
+ for dir in "$@"; do
+ if [[ -n "$dir" && -d "$dir" ]]; then
+ printf '%s' "$dir"
+ return 0
+ fi
+ done
+}
+
+# Like Studio's _host_path: expand ~, and map a Windows path to its WSL mount.
+host_path() {
+ local path="$1"
+ case "$path" in
+ # backslash, not quotes: a quoted ~ reads to shellcheck as a literal tilde
+ # that will never expand (SC2088), and an unquoted one would be expanded
+ # in the pattern itself. Escaped, it matches the literal character.
+ \~ | \~/*) path="$HOME${path:1}" ;;
+ [A-Za-z]:\\* | [A-Za-z]:/*) path="$(wslpath -u "$path" 2>/dev/null)" || path="" ;;
+ esac
+ printf '%s' "$path"
+}
+
+lmstudio_dir() {
+ local settings="$HOME/.lmstudio/settings.json" custom=""
+ local re='"downloadsFolder"[[:space:]]*:[[:space:]]*"([^"]*)"'
+ if [[ -f "$settings" && "$(<"$settings")" =~ $re ]]; then
+ # JSON doubles any backslash in the path
+ custom="$(printf '%s' "${BASH_REMATCH[1]}" | sed 's/\\\\/\\/g')"
+ custom="$(host_path "$custom")"
+ fi
+ first_dir "$custom" "$HOME/.lmstudio/models" "$HOME/.cache/lm-studio/models"
+}
+
+# Mirrors Studio's _hermes_root: a HERMES_HOME outside ~/.hermes is the root, or
+# <root>/profiles/<name> for a profile; downloads land in <root>/models.
+hermes_dir() {
+ local native="$HOME/.hermes" root
+ root="$(host_path "${HERMES_HOME:-}")"
+ root="${root%/}"
+ if [[ -z "$root" || "$root" == "$native" || "$root" == "$native"/* ]]; then
+ root="$native"
+ elif [[ "${root%/*}" == */profiles ]]; then
+ root="${root%/profiles/*}"
+ fi
+ first_dir "$root/models" "$native/models"
+}
+
+ollama_dir() {
+ first_dir "$(host_path "${OLLAMA_MODELS:-}")" "$HOME/.ollama/models" \
+ /usr/share/ollama/.ollama/models /var/lib/ollama/.ollama/models
+}
+
+declare -a MODEL_MOUNTS=()
+mount_models() {
+ local name="$1" dir="$2" target="$3"
+ [[ -z "$dir" || "$dir" == none ]] && return 0
+ if [[ ! -d "$dir" ]]; then
+ printf "\033[1;33mWARN:\033[0m %s models folder %s does not exist; not mounting it.\n" "$name" "$dir" >&2
+ return 0
+ fi
+ [[ "$dir" == /* ]] || dir="$PWD/$dir"
+ MODEL_MOUNTS+=(-v "$dir:$target:ro")
+ printf "Mounting %s models from %s (read-only)\n" "$name" "$dir" >&2
+}
+
+mount_models "LM Studio" "${UNSLOTH_LMSTUDIO_DIR:-$(lmstudio_dir)}" /root/.lmstudio/models
+mount_models Ollama "${UNSLOTH_OLLAMA_DIR:-$(ollama_dir)}" /root/.ollama/models
+mount_models Hermes "${UNSLOTH_HERMES_DIR:-$(hermes_dir)}" /root/.hermes/models
+mount_models local "${UNSLOTH_MODELS_DIR:-}" /workspace/models
+
# Docker resolves --gpus in the DAEMON, before the container exists: on a host with
# no NVIDIA GPU it dies with "failed to discover GPU vendor from CDI: no known GPU
# vendor found" and exit 125, so entrypoint.sh never runs and its diagnostics never
@@ -244,6 +320,7 @@ exec docker run --rm ${TTY_FLAG[@]+"${TTY_FLAG[@]}"} \
-v "$TRITON_CACHE":/workspace/.cache/triton \
-v "$WORK_DIR":/workspace/host \
${STUDIO_MOUNT[@]+"${STUDIO_MOUNT[@]}"} \
+ ${MODEL_MOUNTS[@]+"${MODEL_MOUNTS[@]}"} \
"${ENV_FORWARD[@]}" \
${PORT_FLAGS[@]+"${PORT_FLAGS[@]}"} \
"$IMAGE" "$@"
diff --git a/tests/python/test_docker_run_local_models.py b/tests/python/test_docker_run_local_models.py
new file mode 100644
index 00000000000..e60fb7842fa
--- /dev/null
+++ b/tests/python/test_docker_run_local_models.py
@@ -0,0 +1,280 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+
+import json
+import os
+import shutil
+import stat
+import subprocess
+
+import pytest
+
+_RUN_SH = os.path.join(
+ os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
+ "docker",
+ "run.sh",
+)
+
+pytestmark = pytest.mark.skipif(
+ os.name != "posix" or shutil.which("bash") is None,
+ reason = "POSIX shell required",
+)
+
+_LEAKS = (
+ "HF_HOME",
+ "HF_TOKEN",
+ "HERMES_HOME",
+ "OLLAMA_MODELS",
+ "TRITON_CACHE_DIR",
+ "UNSLOTH_ALLOW_CPU",
+ "UNSLOTH_GPUS",
+ "UNSLOTH_HERMES_DIR",
+ "UNSLOTH_LMSTUDIO_DIR",
+ "UNSLOTH_MODELS_DIR",
+ "UNSLOTH_OLLAMA_DIR",
+ "WANDB_API_KEY",
+)
+
+
+def _run(tmp_path, **env_extra):
+ bindir = tmp_path / "bin"
+ bindir.mkdir(exist_ok = True)
+ argv_log = tmp_path / "argv"
+ docker = bindir / "docker"
+ docker.write_text('#!/usr/bin/env bash\nprintf "%s\\n" "$@" > ' + str(argv_log) + "\n")
+ docker.chmod(docker.stat().st_mode | stat.S_IEXEC)
+
+ env = {k: v for k, v in os.environ.items() if k not in _LEAKS}
+ env.update(
+ PATH = f"{bindir}:/usr/bin:/bin",
+ HOME = str(tmp_path / "home"),
+ UNSLOTH_WORKDIR = str(tmp_path),
+ UNSLOTH_GPUS = "none",
+ **env_extra,
+ )
+ env.pop("PWD", None)
+ proc = subprocess.run(
+ [shutil.which("bash"), _RUN_SH, "true"],
+ cwd = tmp_path,
+ env = env,
+ capture_output = True,
+ text = True,
+ timeout = 60,
+ )
+ assert proc.returncode == 0, proc.stderr
+
+ argv = argv_log.read_text().splitlines()
+ mounts = {}
+ for flag, spec in zip(argv, argv[1:]):
+ if flag != "-v":
+ continue
+ read_only = spec.endswith(":ro")
+ source, target = spec.removesuffix(":ro").rsplit(":", 1)
+ mounts[target] = (os.path.realpath(source), read_only)
+ return mounts, proc.stderr
+
+
+def _dir(path):
+ path.mkdir(parents = True)
+ return os.path.realpath(path)
+
+
+def _fake_wslpath(tmp_path, windows, mapped):
+ bindir = tmp_path / "bin"
+ bindir.mkdir(exist_ok = True)
+ wslpath = bindir / "wslpath"
+ wslpath.write_text(
+ f'#!/usr/bin/env bash\n[[ "$1" == -u && "$2" == \'{windows}\' ]] || exit 1\n'
+ f"printf '%s\\n' '{mapped}'\n"
+ )
+ wslpath.chmod(wslpath.stat().st_mode | stat.S_IEXEC)
+
+
+def test_detected_model_folders_are_mounted_read_only(tmp_path):
+ home = tmp_path / "home"
+ lmstudio = _dir(home / ".lmstudio" / "models")
+ ollama = _dir(home / ".ollama" / "models")
+ hermes = _dir(home / ".hermes" / "models")
+
+ mounts, _ = _run(tmp_path)
+
+ assert mounts["/root/.lmstudio/models"] == (lmstudio, True)
+ assert mounts["/root/.ollama/models"] == (ollama, True)
+ assert mounts["/root/.hermes/models"] == (hermes, True)
+ assert "/workspace/models" not in mounts
+
+
+def test_no_model_folders_adds_no_model_mounts(tmp_path):
+ (tmp_path / "home" / ".lmstudio").mkdir(parents = True)
+ (tmp_path / "home" / ".lmstudio" / "settings.json").write_text("{}")
+
+ mounts, _ = _run(tmp_path, UNSLOTH_OLLAMA_DIR = "none")
+
+ model_targets = {
+ "/root/.lmstudio/models",
+ "/root/.ollama/models",
+ "/root/.hermes/models",
+ "/workspace/models",
+ }
+ assert not model_targets & mounts.keys()
+ assert "/workspace/.cache/huggingface" in mounts
+
+
+def test_lmstudio_downloads_folder_setting_wins(tmp_path):
+ home = tmp_path / "home"
+ _dir(home / ".lmstudio" / "models")
+ custom = _dir(tmp_path / "lmstudio-custom")
+ (home / ".lmstudio" / "settings.json").write_text(
+ json.dumps({"downloadsFolder": custom}, indent = 2)
+ )
+
+ mounts, _ = _run(tmp_path)
+
+ assert mounts["/root/.lmstudio/models"] == (custom, True)
+
+
+def test_lmstudio_downloads_folder_tilde_is_expanded(tmp_path):
+ home = tmp_path / "home"
+ custom = _dir(home / "tilde-models")
+ (home / ".lmstudio").mkdir()
+ (home / ".lmstudio" / "settings.json").write_text(
+ json.dumps({"downloadsFolder": "~/tilde-models"})
+ )
+
+ mounts, _ = _run(tmp_path)
+
+ assert mounts["/root/.lmstudio/models"] == (custom, True)
+
+
+def test_lmstudio_downloads_folder_with_a_backslash_is_json_decoded(tmp_path):
+ home = tmp_path / "home"
+ _dir(home / ".lmstudio" / "models")
+ custom = _dir(tmp_path / "back\\slash models")
+ (home / ".lmstudio" / "settings.json").write_text(json.dumps({"downloadsFolder": custom}))
+
+ mounts, _ = _run(tmp_path)
+
+ assert mounts["/root/.lmstudio/models"] == (custom, True)
+
+
+def test_lmstudio_windows_downloads_folder_is_mapped_under_wsl(tmp_path):
+ home = tmp_path / "home"
+ _dir(home / ".lmstudio" / "models")
+ windows = _dir(tmp_path / "mnt" / "c" / "Users" / "u" / "models")
+ (home / ".lmstudio" / "settings.json").write_text(
+ json.dumps({"downloadsFolder": "C:\\Users\\u\\models"})
+ )
+ _fake_wslpath(tmp_path, "C:\\Users\\u\\models", windows)
+
+ mounts, _ = _run(tmp_path)
+
+ assert mounts["/root/.lmstudio/models"] == (windows, True)
+
+
+def test_custom_hermes_home_is_the_models_root(tmp_path):
+ root = tmp_path / "srv" / "hermes"
+ models = _dir(root / "models")
+
+ mounts, _ = _run(tmp_path, HERMES_HOME = str(root))
+
+ assert mounts["/root/.hermes/models"] == (models, True)
+
+
+def test_hermes_home_tilde_is_expanded(tmp_path):
+ models = _dir(tmp_path / "home" / "hermes-root" / "models")
+
+ mounts, _ = _run(tmp_path, HERMES_HOME = "~/hermes-root")
+
+ assert mounts["/root/.hermes/models"] == (models, True)
+
+
+def test_windows_hermes_home_is_mapped_under_wsl(tmp_path):
+ root = _dir(tmp_path / "mnt" / "d" / "hermes")
+ models = _dir(tmp_path / "mnt" / "d" / "hermes" / "models")
+ _fake_wslpath(tmp_path, "D:\\hermes", root)
+
+ mounts, _ = _run(tmp_path, HERMES_HOME = "D:\\hermes")
+
+ assert mounts["/root/.hermes/models"] == (models, True)
+
+
+def test_hermes_profile_outside_the_home_uses_its_root(tmp_path):
+ root = tmp_path / "data"
+ models = _dir(root / "models")
+ _dir(root / "profiles" / "coder")
+
+ mounts, _ = _run(tmp_path, HERMES_HOME = str(root / "profiles" / "coder"))
+
+ assert mounts["/root/.hermes/models"] == (models, True)
+
+
+def test_hermes_session_home_without_models_keeps_native_models(tmp_path):
+ native = _dir(tmp_path / "home" / ".hermes" / "models")
+ _dir(tmp_path / "session")
+
+ mounts, _ = _run(tmp_path, HERMES_HOME = str(tmp_path / "session"))
+
+ assert mounts["/root/.hermes/models"] == (native, True)
+
+
+def test_legacy_lmstudio_cache_is_found(tmp_path):
+ legacy = _dir(tmp_path / "home" / ".cache" / "lm-studio" / "models")
+
+ mounts, _ = _run(tmp_path)
+
+ assert mounts["/root/.lmstudio/models"] == (legacy, True)
+
+
+def test_ollama_models_env_wins(tmp_path):
+ _dir(tmp_path / "home" / ".ollama" / "models")
+ custom = _dir(tmp_path / "ollama-custom")
+
+ mounts, _ = _run(tmp_path, OLLAMA_MODELS = custom)
+
+ assert mounts["/root/.ollama/models"] == (custom, True)
+
+
+def test_windows_ollama_models_env_is_mapped_under_wsl(tmp_path):
+ _dir(tmp_path / "home" / ".ollama" / "models")
+ windows = _dir(tmp_path / "mnt" / "d" / "ollama")
+ _fake_wslpath(tmp_path, "D:\\ollama", windows)
+
+ mounts, _ = _run(tmp_path, OLLAMA_MODELS = "D:\\ollama")
+
+ assert mounts["/root/.ollama/models"] == (windows, True)
+
+
+def test_explicit_dirs_override_detection(tmp_path):
+ _dir(tmp_path / "home" / ".lmstudio" / "models")
+ lmstudio = _dir(tmp_path / "lmstudio")
+ models = _dir(tmp_path / "gguf")
+
+ mounts, _ = _run(tmp_path, UNSLOTH_LMSTUDIO_DIR = lmstudio, UNSLOTH_MODELS_DIR = "gguf")
+
+ assert mounts["/root/.lmstudio/models"] == (lmstudio, True)
+ assert mounts["/workspace/models"] == (models, True)
+
+
+ "variable, folder, target",
+ [
+ ("UNSLOTH_LMSTUDIO_DIR", ".lmstudio/models", "/root/.lmstudio/models"),
+ ("UNSLOTH_OLLAMA_DIR", ".ollama/models", "/root/.ollama/models"),
+ ("UNSLOTH_HERMES_DIR", ".hermes/models", "/root/.hermes/models"),
+ ],
+)
+def test_none_skips_a_detected_folder(tmp_path, variable, folder, target):
+ _dir(tmp_path / "home" / folder)
+
+ mounts, _ = _run(tmp_path, **{variable: "none"})
+
+ assert target not in mounts
+
+
+def test_a_missing_explicit_dir_warns_and_is_skipped(tmp_path):
+ missing = str(tmp_path / "typo")
+
+ mounts, stderr = _run(tmp_path, UNSLOTH_MODELS_DIR = missing)
+
+ assert "/workspace/models" not in mounts
+ assert missing in stderr