Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(docker): start generated Ollama independently (#6912)

LearningCircuit1b22a5827d8b
diff --git a/changelog.d/+generated-ollama-startup.bugfix.md b/changelog.d/+generated-ollama-startup.bugfix.md
new file mode 100644
index 0000000000..6460a1219d
--- /dev/null
+++ b/changelog.d/+generated-ollama-startup.bugfix.md
@@ -0,0 +1 @@
+Fix fresh generated Docker stacks waiting indefinitely for Ollama. Ollama now starts independently and reports daemon readiness before a model is installed. Generated stacks no longer download the model when they start: install it once after starting the stack with `docker compose -f docker-compose.<name>.yml exec ollama ollama pull <model>`. The generator prints this command when it finishes, and the generated file repeats it in a comment. The generated file also sets `LDR_LLM_MODEL` to the model selected during setup, which locks the model setting in the web UI (the maintained compose file warns about this for the same variable); delete that line to choose the model in the UI.
diff --git a/cookiecutter-docker/hooks/post_gen_project.py b/cookiecutter-docker/hooks/post_gen_project.py
index d5bb1c7fda..5496e38a1b 100644
--- a/cookiecutter-docker/hooks/post_gen_project.py
+++ b/cookiecutter-docker/hooks/post_gen_project.py
@@ -1,5 +1,8 @@
"""
Extracts the compose file from the cookiecutter directory.
+
+When Ollama is enabled it also prints the command that installs the model
+chosen during setup, because the generated stack starts Ollama without one.
"""
import os
@@ -8,6 +11,9 @@ import time
from pathlib import Path
COMPOSE_FILE_NAME = "docker-compose.{{cookiecutter.config_name}}.yml"
+# Answers recorded by pre_prompt.py; cookiecutter renders them into this file.
+OLLAMA_ENABLED = "{{ cookiecutter._enable_ollama }}".lower() == "true"
+OLLAMA_MODEL = "{{ cookiecutter._ollama_model }}"
def rmtree_with_retry(
@@ -37,6 +43,25 @@ def rmtree_with_retry(
raise last_error
+def print_model_install_hint() -> None:
+ """
+ Print the command that installs the Ollama model chosen during setup.
+
+ The generated Ollama service starts without any model and LDR does not
+ download one, so the first research fails until the model is installed.
+ """
+ if not OLLAMA_ENABLED:
+ return
+ print(
+ "\nOllama starts without a model. After starting the stack with\n"
+ f" docker compose -f {COMPOSE_FILE_NAME} up -d\n"
+ "install the model you selected during setup:\n"
+ f" docker compose -f {COMPOSE_FILE_NAME} exec ollama "
+ f"ollama pull {OLLAMA_MODEL}\n"
+ "(If you set MODEL when starting the stack, pull that model instead.)"
+ )
+
+
def main():
# Move the compose file one directory up.
compose_path = Path(COMPOSE_FILE_NAME)
@@ -52,6 +77,8 @@ def main():
else:
shutil.rmtree(output_dir)
+ print_model_install_hint()
+
if __name__ == "__main__":
main()
diff --git a/cookiecutter-docker/{{cookiecutter.config_name}}/docker-compose.{{cookiecutter.config_name}}.yml b/cookiecutter-docker/{{cookiecutter.config_name}}/docker-compose.{{cookiecutter.config_name}}.yml
index 967ffd7751..9716ab1c94 100644
--- a/cookiecutter-docker/{{cookiecutter.config_name}}/docker-compose.{{cookiecutter.config_name}}.yml
+++ b/cookiecutter-docker/{{cookiecutter.config_name}}/docker-compose.{{cookiecutter.config_name}}.yml
@@ -25,6 +25,7 @@ services:
{%- if cookiecutter._enable_ollama %}
- LDR_LLM_PROVIDER=ollama
- LDR_LLM_OLLAMA_URL=http://ollama:11434
+ - LDR_LLM_MODEL=${MODEL:-{{ cookiecutter._ollama_model }}}
{% endif %}
{%- if cookiecutter.enable_searxng %}
- LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_INSTANCE_URL=http://searxng:8080
@@ -68,18 +69,21 @@ services:
image: ollama/ollama:latest
{% endif %}
container_name: ollama_service
- entrypoint: "/scripts/ollama_entrypoint.sh ${MODEL:-{{ cookiecutter._ollama_model }}}"
+ # Use the image's own `ollama serve` entrypoint so a fresh data volume
+ # can start independently of the LDR container.
+ # After starting the stack, install the model selected during setup:
+ # docker compose -f docker-compose.{{cookiecutter.config_name}}.yml exec ollama ollama pull {{ cookiecutter._ollama_model }}
+ # If MODEL is overridden, pull that model instead.
healthcheck:
- test: [ "CMD", "ollama", "show", "${MODEL:-{{ cookiecutter._ollama_model }}}" ]
+ test: [ "CMD", "ollama", "list" ]
interval: 10s
timeout: 5s
- start_period: 10m
- retries: 2
+ start_period: 30s
+ retries: 5
environment:
OLLAMA_KEEP_ALIVE: '30m'
volumes:
- ollama_data:/root/.ollama
- - ldr_scripts:/scripts
{%- if not cookiecutter.host_network %}
networks:
- ldr-network
diff --git a/docs/docker-compose-guide.md b/docs/docker-compose-guide.md
index 74c7ddb6aa..7fbc9705e4 100644
--- a/docs/docker-compose-guide.md
+++ b/docs/docker-compose-guide.md
@@ -131,6 +131,19 @@ Then start with:
docker compose -f docker-compose.default.yml up -d
```
+Cookie Cutter also asks whether to enable Ollama and which model to use. The
+generated Ollama service starts without any model and nothing downloads it
+for you, so install the model you chose once after starting the stack. Cookie
+Cutter prints this command when it finishes:
+
+```bash
+docker compose -f docker-compose.default.yml exec ollama ollama pull <model>
+```
+
+The generated file also sets `LDR_LLM_MODEL` to that model, which locks the
+model setting in the web UI. Delete that line from the generated file if you
+want to choose the model in the UI.
+
## Using External LLM Providers
### OpenRouter (100+ Models)
diff --git a/docs/faq.md b/docs/faq.md
index a9929a7bdf..625171a26f 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -162,12 +162,17 @@ For a complete reference of all settings, defaults, and environment variables, s
### How do I download Ollama models in Docker?
-**Note**: If you use cookiecutter with Ollama, it will automatically download an initial model that you specify during setup.
+The Ollama container starts without any model, and LDR does not download one for you. Pull each model you want once; it is kept in the `ollama_data` volume.
-To manually download additional models:
+**Note**: If you use cookiecutter with Ollama, the generated file points LDR at the model you chose during setup (`LDR_LLM_MODEL`) but does not install it. The generator prints the exact command when it finishes; run it once after starting the stack:
```bash
-# Connect to the Ollama container
-docker exec -it ollama ollama pull llama3:8b
+docker compose -f docker-compose.<config_name>.yml exec ollama ollama pull <model>
+```
+
+To download any other model:
+```bash
+# Connect to the Ollama container (named ollama_service in the compose files)
+docker exec -it ollama_service ollama pull llama3:8b
# Or if using docker-compose
docker-compose exec ollama ollama pull llama3:8b
diff --git a/tests/deployment/test_deployment_surface_contracts.py b/tests/deployment/test_deployment_surface_contracts.py
index e66bc3d56b..b9af6e8bad 100644
--- a/tests/deployment/test_deployment_surface_contracts.py
+++ b/tests/deployment/test_deployment_surface_contracts.py
@@ -695,15 +695,8 @@ def nginx_block_from_doc(path: Path) -> str:
return fence.group(1)
-def render_cookiecutter(**overrides) -> dict:
- """Render the cookiecutter compose template and parse it as YAML."""
- jinja2 = pytest.importorskip("jinja2")
- template_dir = COOKIECUTTER_DIR / "{{cookiecutter.config_name}}"
- template_files = sorted(template_dir.iterdir())
- assert len(template_files) == 1, (
- "cookiecutter template dir shape changed; expected exactly one "
- f"compose template, got {[p.name for p in template_files]}"
- )
+def cookiecutter_context(**overrides) -> dict:
+ """The cookiecutter.json defaults plus what pre_prompt.py injects."""
context = json.loads(
(COOKIECUTTER_DIR / "cookiecutter.json").read_text(encoding="utf-8")
)
@@ -713,10 +706,61 @@ def render_cookiecutter(**overrides) -> dict:
context.setdefault("_nvidia_gpu", True)
context.setdefault("_amd_gpu", False)
context.update(overrides)
- rendered = jinja2.Template(
+ return context
+
+
+def render_cookiecutter_text(**overrides) -> str:
+ """Render the cookiecutter compose template to text, comments included."""
+ jinja2 = pytest.importorskip("jinja2")
+ template_dir = COOKIECUTTER_DIR / "{{cookiecutter.config_name}}"
+ template_files = sorted(template_dir.iterdir())
+ assert len(template_files) == 1, (
+ "cookiecutter template dir shape changed; expected exactly one "
+ f"compose template, got {[p.name for p in template_files]}"
+ )
+ return jinja2.Template(
template_files[0].read_text(encoding="utf-8")
- ).render(cookiecutter=SimpleNamespace(**context))
- return yaml.safe_load(rendered)
+ ).render(cookiecutter=SimpleNamespace(**cookiecutter_context(**overrides)))
+
+
+def render_cookiecutter(**overrides) -> dict:
+ """Render the cookiecutter compose template and parse it as YAML."""
+ return yaml.safe_load(render_cookiecutter_text(**overrides))
+
+
+def run_post_gen_hook(tmp_path: Path, **overrides) -> str:
+ """Render the post-gen hook, run it in a generated project, return stdout.
+
+ Cookiecutter renders the hook as a Jinja template and runs it with the
+ generated project directory as the working directory.
+ """
+ jinja2 = pytest.importorskip("jinja2")
+ context = cookiecutter_context(**overrides)
+ hook = tmp_path / "post_gen_project.py"
+ hook.write_text(
+ jinja2.Template(
+ (COOKIECUTTER_DIR / "hooks" / "post_gen_project.py").read_text(
+ encoding="utf-8"
+ )
+ ).render(cookiecutter=SimpleNamespace(**context)),
+ encoding="utf-8",
+ )
+ compose_name = f"docker-compose.{context['config_name']}.yml"
+ project = tmp_path / "out" / context["config_name"]
+ project.mkdir(parents=True)
+ (project / compose_name).write_text("services: {}\n", encoding="utf-8")
+ result = subprocess.run(
+ [sys.executable, str(hook)],
+ cwd=project,
+ capture_output=True,
+ text=True,
+ check=True,
+ timeout=60,
+ )
+ # The hook moves the compose file up and removes the project directory.
+ assert (project.parent / compose_name).is_file()
+ assert not project.exists()
+ return result.stdout
def env_list_to_dict(service: dict) -> dict[str, str]:
@@ -2133,22 +2177,6 @@ class TestCookiecutterTemplate:
assert "@sha256:" in rendered[name]["image"], name
assert "@sha256:" in compose_base["services"][name]["image"]
- @pytest.mark.xfail(
- strict=True,
- reason=(
- "DEFECT: the generated ollama service sets 'entrypoint: "
- "/scripts/ollama_entrypoint.sh ...' and mounts the ldr_scripts "
- "named volume, but that script only exists inside the LDR "
- "image -- Docker seeds a named volume from the image of the "
- "container that mounts it, and the ollama image has no "
- "/scripts. Meanwhile the LDR service waits on "
- "'depends_on: ollama: condition: service_healthy'. On a fresh "
- "stack ollama starts first against an empty volume, its "
- "entrypoint is not found, it never becomes healthy, and LDR "
- "never starts. The maintained compose avoids this by using the "
- "upstream ollama entrypoint."
- ),
- )
def test_generated_ollama_does_not_depend_on_ldr_owned_scripts(self):
rendered = render_cookiecutter()["services"]
ollama = rendered["ollama"]
@@ -2167,6 +2195,60 @@ class TestCookiecutterTemplate:
f"populates: {entrypoint!r}"
)
+ @pytest.mark.parametrize("gpu", ["cpu", "nvidia", "amd"])
+ def test_fresh_ollama_readiness_does_not_require_an_installed_model(
+ self, gpu
+ ):
+ services = render_cookiecutter(
+ _ollama_model="selected-model:latest",
+ enable_gpu=gpu != "cpu",
+ _nvidia_gpu=gpu == "nvidia",
+ _amd_gpu=gpu == "amd",
+ )["services"]
+ ollama = services["ollama"]
+ assert "entrypoint" not in ollama
+ assert "command" not in ollama
+ assert ollama["healthcheck"]["test"] == ["CMD", "ollama", "list"]
+ assert ollama["volumes"] == ["ollama_data:/root/.ollama"]
+ assert env_list_to_dict(services[LDR_SERVICE])["LDR_LLM_MODEL"] == (
+ "${MODEL:-selected-model:latest}"
+ )
+
+ def test_disabled_ollama_does_not_configure_an_ollama_model(self):
+ services = render_cookiecutter(_enable_ollama=False)["services"]
+ assert "ollama" not in services
+ assert "LDR_LLM_MODEL" not in env_list_to_dict(services[LDR_SERVICE])
+
+ def test_post_gen_hook_prints_the_exact_model_install_command(
+ self, tmp_path
+ ):
+ overrides = {
+ "config_name": "demo",
+ "_ollama_model": "selected-model:latest",
+ }
+ command = (
+ "docker compose -f docker-compose.demo.yml exec ollama "
+ "ollama pull selected-model:latest"
+ )
+ assert command in run_post_gen_hook(tmp_path, **overrides)
+ # The generated file documents the same command in a comment.
+ assert f"# {command}" in render_cookiecutter_text(**overrides)
+
+ def test_post_gen_hook_is_silent_when_ollama_is_disabled(self, tmp_path):
+ output = run_post_gen_hook(tmp_path, _enable_ollama=False)
+ assert "ollama" not in output.lower()
+
+ def test_faq_does_not_promise_an_automatic_model_download(self):
+ faq = (REPO_ROOT / "docs" / "faq.md").read_text(encoding="utf-8")
+ heading = "### How do I download Ollama models in Docker?"
+ section = faq.split(heading)[1].split("\n### ")[0]
+ container = render_cookiecutter()["services"]["ollama"][
+ "container_name"
+ ]
+ assert "automatically download" not in section
+ assert "exec ollama ollama pull <model>" in section
+ assert f"docker exec -it {container} ollama pull" in section
+
@pytest.mark.xfail(
strict=True,
reason=(