automate docker network config for ollama on linux#81
Conversation
| # if [ "$(uname)" = "Linux" ]; then | ||
| if [ "$(uname)" = "Linux" ] && grep -q AI_BACKEND="ollama" .env; then | ||
| printf "set host.docker.internal" | ||
| docker exec bee-stack-bee-api-1 sh -c "echo \"\$(ip route | awk '/default/ { print \$3 }' | head -n 1) host.docker.internal\" | tee -a /etc/hosts > /dev/null" |
There was a problem hiding this comment.
is it actually necessary to add host.docker.internal to /etc/hosts?
Maybe we can reconsider just adding this using extra_hosts in docker-compose file. I did that some time ago but removed it because there was a problem with an older version of podman. Might be resloved now, we don't support old versions anyway.
Using ip route is not robust imo - it requires ip tool which is not installed on all distros by default I assume (?), plus this is not officially supported way to find and expose the bridge network from inside the container, the networking might be more complex and implemented differently in some runtimes, I think this is an implementation detail only for docker and might break in podman for example.
There was a problem hiding this comment.
In this change I've just automated the suggestion from the troublehooting guide, with the least amout of change. I cannot speak for the extra_hosts solution as I've not tested that. What I can say: this has worked for me and it's definitely eliminate the extra manual step from the troubleshooting guide, plus it also resolves the blocker setup issue in case of ollama AI backend (which has also attempted to address in #80 ).
Is there a more elegant solution for this, probably yes, but now it's better than the current state.
There was a problem hiding this comment.
Maybe we can reconsider just adding this using extra_hosts in docker-compose file.
The problem that I encountered with using extra_hosts is that uses the default docker bridge network (gateway on my machine is 172.17.0.1), while the bee-stack creates its own bridge network (bee-stack_default, gateway on my machine 172.21.0.1). Since the gateway for the bee bridge network won't be known until it is created, I don't think we can use the compose file here.
There was a problem hiding this comment.
it requires ip tool which is not installed on all distros by default
as long as we have it in the bee-api image we should be ok
There was a problem hiding this comment.
So what's the decision?
I've automated the linux ollama setup issue mentioned here:
https://github.com/i-am-bee/bee-stack/blob/main/docs/troubleshooting.md#connecting-to-ollama-on-linux
This change affects configure_ollama() and the start_stack()
configure_ollama
in case the the OS is Linux and the OLLAMA_URL is the default, the ollama check also updates
the /etc/hosts on the fly there for the command can succeed if ollama is binded to 0.0.0.0 on the host OS.
start_stack
updates the /etc/hosts in bee-stack-bee-api-1
Manually tested on
Linux version 6.1.0-28-amd64 (debian-kernel@lists.debian.org) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT_DYNAMIC Debian 6.1.119-1 (2024-11-22)
Docker version 20.10.24+dfsg1, build 297e128