{"id":3175,"date":"2026-06-26T07:48:09","date_gmt":"2026-06-26T07:48:09","guid":{"rendered":"https:\/\/tucumandevelopers.com\/index.php\/2026\/06\/26\/self-hosted-ollama-homelab-3-mistakes-running-local-llms\/"},"modified":"2026-06-26T07:48:09","modified_gmt":"2026-06-26T07:48:09","slug":"self-hosted-ollama-homelab-3-mistakes-running-local-llms","status":"publish","type":"post","link":"https:\/\/tucumandevelopers.com\/index.php\/2026\/06\/26\/self-hosted-ollama-homelab-3-mistakes-running-local-llms\/","title":{"rendered":"Self-Hosted Ollama Homelab: 3 Mistakes Running Local LLMs"},"content":{"rendered":"<div>Originally published on kuryzhev.cloud<br \/>\nWe thought setting up a self-hosted Ollama homelab for DevOps assistance would take an afternoon. Three OOM crashes, one exposed API endpoint, and a silent CPU fallback later, here&#8217;s what actually works \u2014 and what we&#8217;d do differently from day one.<br \/>\nContext: Why We Wanted a Local LLM for Homelab Automation<br \/>\nOur homelab runs a fairly typical self-hosted DevOps stack: Gitea for source control, Drone CI for pipelines, Proxmox for VM management, and a handful of Docker Compose services scattered across two physical hosts. Day-to-day tasks involve writing Ansible playbooks, debugging systemd units, generating Dockerfiles, and occasionally reverse-engineering someone else&#8217;s Terraform. All of that involves a lot of back-and-forth with language models.<br \/>\nThe problem with cloud-based LLM APIs \u2014 ChatGPT, Claude, Gemini \u2014 is that they require pasting real infrastructure configs into a browser. Hostnames, internal IP ranges, secrets that slipped into a playbook comment, service account names. None of that should leave the network. We also have air-gapped lab segments that physically can&#8217;t reach the internet, and we wanted consistent tooling across both environments.<br \/>\nWe chose Ollama for a few concrete reasons: it ships as a single binary, it manages model downloads via a clean CLI, and it exposes an OpenAI-compatible REST API on port 11434 out of the box. That last point matters \u2014 it means any tool that supports the OpenAI API (Continue.dev in VS Code, shell scripts using curl, custom Python utilities) works against Ollama without modification. The plan was straightforward. The execution was not.<br \/>\nMistake 1: Assuming Any GPU Would &#8220;Just Work&#8221; with Ollama<br \/>\nThe first host we tried had an NVIDIA GTX 1060 3GB installed. We ran ollama run llama3, watched it load, and immediately noticed something was wrong. Inference was crawling at roughly 2 tokens per second. We expected 25 or more. No error. No warning. The model just loaded silently into system RAM and ran entirely on CPU.<br \/>\nWe burned two hours checking the wrong things \u2014 model quantization, RAM speed, thermal throttling \u2014 before running ollama ps and seeing 100% CPU next to the loaded model. Then we checked the logs with OLLAMA_DEBUG=1 ollama serve and found the real message:<br \/>\nmsg=&#8221;no GPU detected&#8221;<br \/>\nThe GTX 1060 was visible to nvidia-smi. The driver was loaded. But Ollama requires CUDA 11.8 or higher, and that host was running CUDA 11.4. The mismatch was silent from the client&#8217;s perspective \u2014 Ollama simply fell back to CPU without surfacing any error to the caller.<br \/>\nWatch out for this: nvidia-smi showing your GPU does not mean Ollama will use it. Always verify with OLLAMA_DEBUG=1 and look for offload layers: 32\/32 in the output. That line confirms full GPU acceleration. Anything less means partial or zero offload.<br \/>\nThe fix required three steps: updating the CUDA toolkit to 11.8, pinning nvidia-container-toolkit to version 1.14.3 (earlier versions had inconsistent behavior with Docker runtime detection), and ensuring \/etc\/docker\/daemon.json had &#8220;default-runtime&#8221;: &#8220;nvidia&#8221; set. After that, the same model ran at 28 tokens per second on the same hardware. Same model, same host, completely different experience.<br \/>\nWe also verified the CUDA version properly this time:<br \/>\n# Check CUDA version \u2014 must be >= 11.8 for Ollama GPU support<br \/>\nnvcc &#8211;version<\/p>\n<p># Confirm Docker is using the nvidia runtime<br \/>\ndocker info | grep -i runtime<\/p>\n<p># Verify GPU offload after starting Ollama with debug logging<br \/>\nOLLAMA_DEBUG=1 ollama serve 2>&#038;1 | grep -i &#8220;offload layers&#8221;<br \/>\nMistake 2: Running Ollama Directly on the Host Without Resource Limits<br \/>\nOnce GPU acceleration was working, we got greedy and pulled a larger model. codellama:13b seemed like the right tool for generating longer Ansible roles and reviewing Dockerfiles with more context. We pulled it, ran it, and about forty seconds into the first inference request, everything went sideways.<br \/>\nThe OOM killer fired. It took down our Gitea container mid-push. A developer on the team lost a commit they hadn&#8217;t pushed yet. The codellama:13b model in Q4_K_M quantization needs roughly 8.5GB of VRAM \u2014 and on a 16GB host already running a dozen services, the model load spiked total RAM consumption to 14GB instantaneously. The kernel picked Gitea as the most expendable process. It wasn&#8217;t.<br \/>\nThe root cause was straightforward: we were running Ollama directly on the host with no cgroup constraints, no memory limits, and no model eviction policy. In Ollama v0.1.38 and later, OLLAMA_MAX_LOADED_MODELS controls how many models stay resident in memory simultaneously. In earlier versions, there&#8217;s no eviction control at all. We hadn&#8217;t set either OLLAMA_MAX_LOADED_MODELS or OLLAMA_NUM_PARALLEL, so Ollama defaulted to greedy behavior \u2014 loading whatever was asked, keeping it resident, and accepting parallel requests that multiplied memory pressure.<br \/>\nWatch out for this: OLLAMA_NUM_PARALLEL defaults to 4 in recent versions. On a constrained homelab host, four simultaneous inference requests against a 7B model will absolutely OOM your other services. Set it to 1 unless you have dedicated hardware.<br \/>\nThe correct approach was to containerize Ollama with explicit resource caps and isolate it from critical services on a dedicated Docker network. We moved everything into Docker Compose, set mem_limit: 10g, and added environment variables to enforce single-model, single-request behavior.<br \/>\nMistake 3: Exposing the Ollama API Without Authentication<br \/>\nThis one is embarrassing to admit. The default ollama serve binds to 127.0.0.1, which is fine for bare-metal installs. But our Docker Compose setup used ports: &#8220;11434:11434&#8221; without thinking through what that means on a flat home network. It published the port to every interface on the host \u2014 which sits on the same physical switch as our IoT VLAN due to a pfSense VLAN rule we&#8217;d misconfigured months earlier.<br \/>\nOllama has no built-in authentication as of v0.1.x. Anyone who could reach port 11434 could call GET \/api\/tags to enumerate loaded models, send inference requests, or \u2014 and this is the one that actually worried us \u2014 trigger a POST \/api\/pull to download a multi-gigabyte model and exhaust disk space. There&#8217;s no rate limiting either. A single unauthenticated pull request from a compromised IoT device could fill a volume.<br \/>\nWe also had OLLAMA_HOST=0.0.0.0 set inside the container, which is necessary for the container&#8217;s internal binding but easy to misread as &#8220;only affects the container namespace.&#8221; It doesn&#8217;t change the fact that the Docker port mapping exposes it externally.<br \/>\nThe fix was an Nginx reverse proxy with HTTP Basic Auth sitting in front of Ollama, combined with binding the proxy&#8217;s published port to 127.0.0.1:8080 on the host. Remote access goes through Tailscale, which restricts it to trusted nodes only. For the health check endpoint used by monitoring tools, we carved out an auth-exempt location \/api\/tags block in Nginx.<br \/>\nWhat We Do Differently Now: A Stable, Reproducible Ollama Stack<br \/>\nThe current setup avoids all three mistakes. Here&#8217;s the full Docker Compose configuration we run in production on the homelab. It uses a pinned Ollama image, GPU passthrough via the nvidia runtime, hard memory caps, and an Nginx auth proxy \u2014 all wired together with a named volume for model persistence.<br \/>\nThis Docker Compose file defines the full hardened stack. Read the inline comments carefully \u2014 several of the environment variables are non-obvious in their effect:<br \/>\n# docker-compose.yml \u2014 Production-hardened Ollama stack for homelab<br \/>\n# Tested with Ollama v0.1.38, Docker 24.x, nvidia-container-toolkit 1.14.3<\/p>\n<p>version: &#8220;3.9&#8221;<\/p>\n<p>services:<br \/>\n  ollama:<br \/>\n    image: ollama\/ollama:0.1.38          # pinned \u2014 avoid surprise API changes<br \/>\n    container_name: ollama<br \/>\n    restart: unless-stopped<br \/>\n    runtime: nvidia                       # requires nvidia-container-toolkit<br \/>\n    environment:<br \/>\n      &#8211; OLLAMA_HOST=0.0.0.0              # bind inside container; proxy handles external auth<br \/>\n      &#8211; OLLAMA_NUM_PARALLEL=1            # prevent concurrent request memory spikes<br \/>\n      &#8211; OLLAMA_MAX_LOADED_MODELS=1       # evict previous model before loading new one<br \/>\n      &#8211; OLLAMA_DEBUG=0                   # set to 1 temporarily to verify GPU offload layers<br \/>\n    volumes:<br \/>\n      &#8211; ollama_models:\/root\/.ollama      # persist models across container rebuilds<br \/>\n    networks:<br \/>\n      &#8211; ollama_internal                  # isolated from critical services network<br \/>\n    deploy:<br \/>\n      resources:<br \/>\n        limits:<br \/>\n          memory: 10g                    # hard cap \u2014 prevents OOM-killing neighbors<br \/>\n        reservations:<br \/>\n          devices:<br \/>\n            &#8211; driver: nvidia<br \/>\n              count: 1<br \/>\n              capabilities: [gpu]<br \/>\n    healthcheck:<br \/>\n      test: [&#8220;CMD&#8221;, &#8220;curl&#8221;, &#8220;-f&#8221;, &#8220;http:\/\/localhost:11434\/api\/tags&#8221;]<br \/>\n      interval: 30s<br \/>\n      timeout: 10s<br \/>\n      retries: 3<br \/>\n      start_period: 20s                  # model server takes ~15s to initialize<\/p>\n<p>  ollama-proxy:<br \/>\n    image: nginx:1.25-alpine<br \/>\n    container_name: ollama-proxy<br \/>\n    restart: unless-stopped<br \/>\n    ports:<br \/>\n      &#8211; &#8220;127.0.0.1:8080:80&#8221;             # bind to loopback only; use Tailscale for remote access<br \/>\n    volumes:<br \/>\n      &#8211; .\/nginx\/ollama.conf:\/etc\/nginx\/conf.d\/default.conf:ro<br \/>\n      &#8211; .\/nginx\/.htpasswd:\/etc\/nginx\/.htpasswd:ro<br \/>\n    networks:<br \/>\n      &#8211; ollama_internal<br \/>\n    depends_on:<br \/>\n      ollama:<br \/>\n        condition: service_healthy<\/p>\n<p>volumes:<br \/>\n  ollama_models:<br \/>\n    driver: local<\/p>\n<p>networks:<br \/>\n  ollama_internal:<br \/>\n    driver: bridge<br \/>\n    internal: false                      # set true if Ollama should have no outbound internet<br \/>\nThe Nginx config below handles streaming inference correctly. The two most common mistakes people make here are forgetting proxy_buffering off (which causes the response to appear all at once instead of streaming) and leaving proxy_read_timeout at the default 60 seconds, which causes 504 errors mid-generation on longer prompts:<br \/>\n# nginx\/ollama.conf \u2014 Reverse proxy with Basic Auth for Ollama API<br \/>\n# Generate .htpasswd: htpasswd -c nginx\/.htpasswd devops<br \/>\n# Set proxy_read_timeout high \u2014 streaming inference takes time<\/p>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name _;<\/p>\n<p>    # Basic auth \u2014 replace with mTLS for higher-security environments<br \/>\n    auth_basic           &#8220;Ollama API&#8221;;<br \/>\n    auth_basic_user_file \/etc\/nginx\/.htpasswd;<\/p>\n<p>    location \/ {<br \/>\n        proxy_pass         http:\/\/ollama:11434;<br \/>\n        proxy_http_version 1.1;<\/p>\n<p>        # Critical: streaming responses require these headers<br \/>\n        proxy_set_header   Connection &#8221;;<br \/>\n        proxy_buffering    off;<br \/>\n        proxy_cache        off;<\/p>\n<p>        # Increase timeouts \u2014 default 60s causes 504 on long generations<br \/>\n        proxy_read_timeout    300s;<br \/>\n        proxy_connect_timeout 10s;<br \/>\n        proxy_send_timeout    300s;<\/p>\n<p>        proxy_set_header Host $host;<br \/>\n        proxy_set_header X-Real-IP $remote_addr;<br \/>\n    }<\/p>\n<p>    # Health endpoint \u2014 exempt from auth for monitoring tools<br \/>\n    location \/api\/tags {<br \/>\n        auth_basic off;<br \/>\n        proxy_pass http:\/\/ollama:11434\/api\/tags;<br \/>\n    }<br \/>\n}<br \/>\nFor model selection, we settled on two workhorses that fit within 6GB VRAM with quantization: codellama:7b in Q4_K_M for quick completions and inline code suggestions, and mistral:7b-instruct-v0.2-q4_K_M for longer reasoning tasks like reviewing a Terraform plan or explaining a failing systemd unit. The 13B models sound appealing but they&#8217;re genuinely impractical on homelab hardware unless you have a dedicated GPU with 10GB+ VRAM.<br \/>\nWe also pin models using digest references in our Modelfiles \u2014 FROM llama3:8b-instruct@sha256:abc123&#8230; \u2014 so a weekly ollama pull cron job doesn&#8217;t silently swap out a model we&#8217;ve tuned prompts for. Model versioning matters more than most people realize when you&#8217;re building automation on top of LLM output.<br \/>\nFor observability, Ollama has no native Prometheus endpoint, so we rely on ollama ps and ollama list in a lightweight cron-based check, plus the Docker healthcheck defined in the Compose file. It&#8217;s not elegant, but it catches the cases that actually happen: the model server failing to start, or a model getting stuck in a loading state. More details on our homelab monitoring approach are over at kuryzhev.cloud.<br \/>\nRunning a self-hosted Ollama homelab is genuinely useful once the stack is stable. The self-hosted Ollama homelab we have now handles dozens of DevOps assistance requests per day with zero data leaving the network, predictable resource usage, and a setup that survives container restarts and host reboots without manual intervention. Getting there required making all three of these mistakes first \u2014 hopefully this saves you the OOM crashes.<br \/>\nRelated<br \/>\nMore Docker Compose production patterns and service hardening<br \/>\nHomelab monitoring, alerting, and observability setups<br \/>\nContainer and network security configurations for self-hosted stacks<\/p><\/div>\n<p>Fuente: <a href=\"https:\/\/dev.to\/oleksandr_kuryzhev_42873f\/self-hosted-ollama-homelab-3-mistakes-running-local-llms-11l1\">Art\u00edculo original<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Originally published on kuryzhev.cloud We thought setting up a self-hosted Ollama homelab for DevOps assistance would take an afternoon. Three OOM crashes, one exposed API endpoint, and a silent CPU fallback later, here&#8217;s what actually works \u2014 and what we&#8217;d do differently from day one. Context: Why We Wanted a Local LLM for Homelab Automation [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2648,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[41],"tags":[],"class_list":["post-3175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devto"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/3175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/comments?post=3175"}],"version-history":[{"count":0,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/3175\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/media\/2648"}],"wp:attachment":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/media?parent=3175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/categories?post=3175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/tags?post=3175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}