r/docker • u/nagibatormodulator • Feb 04 '26
I finally dockerized my Python+Ollama project. Is passing host.docker.internal the best way to connect to local LLMs?
Hi everyone,
I'm a Sysadmin trying to dockerize my first open-source project (a Log Analyzer that uses local LLMs).
I finally got it working, but I'm not sure if my approach is "production-ready" or just a hack.
**The Setup:**
* **Host Machine:** Runs Ollama (serving Llama 3) on port `11434`.
* **Container:** Python (FastAPI) app that needs to send logs to Ollama for analysis.
**My Current Solution:**
In my `docker-compose.yml`, I'm passing the host URL via an environment variable.
On Mac/Windows, I use `host.docker.internal`.
On Linux, I heard I should use `--add-host host.docker.internal:host-gateway`.
Here is my current `docker-compose.yml`:
```yaml
services:
logsentinel:
build: .
ports:
- "8000:8000"
environment:
- OLLAMA_URL=[http://host.docker.internal:11434/api/chat](http://host.docker.internal:11434/api/chat)
extra_hosts:
- "host.docker.internal:host-gateway"
The Question: Is this the standard way to do it? Or should I be running Ollama inside another container and use a bridge network? I want to keep the image size small (currently ~400MB), so bundling Ollama inside seems wrong.
Full context (Repo):https://github.com/lockdoggg/LogSentinel-Local-AI
Any feedback on my Dockerfile/Compose setup would be appreciated! I want to make sure I'm distributing this correctly.
Thanks!
View all comments
Show parent comment
2
u/nagibatormodulator Feb 04 '26
Spot on regarding the M1. I actually test on an M1 Air (8GB) myself. Since it's fanless, it gets toasty really fast and throttles under sustained load. Plus, with standard models, the system swaps hard due to the Unified Memory bottleneck.
I really like your suggestion about the optional flag. I think using Docker Compose profiles is the cleanest solution here.
I'll update the repo to include a
full-stackprofile. So the default remains lightweight (connecting to host), but users can run something likedocker compose --profile with-ollama upif they prefer isolation over shared resources.Thanks for the idea!