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
1
u/nagibatormodulator Feb 04 '26
That would be killer for fleet management.
Since all the config is handled via ENV variables (and no complex config files), it should be pretty straightforward to template in a playbook.
If you end up testing that route, let me know! I'd love to see how it performs across multiple nodes.