Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

automate docker network config for ollama on linux#81

Open
csabakecskemeti wants to merge 2 commits into
i-am-bee:mainfrom
csabakecskemeti:automate_manual_cfg_steps_for_ollama_on_linux
Open

automate docker network config for ollama on linux#81
csabakecskemeti wants to merge 2 commits into
i-am-bee:mainfrom
csabakecskemeti:automate_manual_cfg_steps_for_ollama_on_linux

Conversation

@csabakecskemeti

@csabakecskemeti csabakecskemeti commented Jan 19, 2025

Copy link
Copy Markdown

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

Comment thread bee-stack.sh Outdated
Comment thread bee-stack.sh Outdated
Comment thread bee-stack.sh
# 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"

@jezekra1 jezekra1 Jan 20, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@csabakecskemeti csabakecskemeti Jan 20, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@psschwei psschwei Jan 22, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what's the decision?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jezekra1 what do you think?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants