[GH-ISSUE #5879] Definiting a host in /etc/hosts doesn't work #50179

Closed
opened 2026-04-28 14:33:28 -05:00 by GiteaMirror · 24 comments
Owner

Originally created by @JayCroghan on GitHub (Jul 23, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/5879

What is the issue?

I am trying to set a hostname in /etc/hosts and it works fine for ping but ollama gives the following output:

somedomain.com below most definitely does not exist.

  ___                    __        __   _     _   _ ___
 / _ \ _ __   ___ _ __   \ \      / /__| |__ | | | |_ _|
| | | | '_ \ / _ \ '_ \   \ \ /\ / / _ \ '_ \| | | || |
| |_| | |_) |  __/ | | |   \ V  V /  __/ |_) | |_| || |
 \___/| .__/ \___|_| |_|    \_/\_/ \___|_.__/ \___/|___|
      |_|


v0.3.6 - building the best open-source AI user interface.

https://github.com/open-webui/open-webui

INFO:apps.openai.main:get_all_models()
INFO:apps.ollama.main:get_all_models()
ERROR:apps.ollama.main:Connection error: Cannot connect to host somedomain.com:11434 ssl:default [Name or service not known]
INFO:     192.168.2.108:0 - "GET /ws/socket.io/?EIO=4&transport=polling&t=P3W7LDd HTTP/1.0" 200 OK
INFO:apps.openai.main:get_all_models()
INFO:apps.ollama.main:get_all_models()
ERROR:apps.ollama.main:Connection error: Cannot connect to host somedomain.com:11434 ssl:default [Name or service not known]
INFO:     192.168.2.108:0 - "POST /ws/socket.io/?EIO=4&transport=polling&t=P3W7LZz&sid=qzoO8V8hGw4XAjT7AAAA HTTP/1.0" 200 OK
INFO:apps.openai.main:get_all_models()
INFO:apps.ollama.main:get_all_models()
INFO:apps.openai.main:get_all_models()
INFO:apps.ollama.main:get_all_models()
ERROR:apps.ollama.main:Connection error: Cannot connect to host somedomain.com:11434 ssl:default [Name or service not known]
INFO:     192.168.2.108:0 - "GET /ws/socket.io/?EIO=4&transport=websocket&sid=qzoO8V8hGw4XAjT7AAAA HTTP/1.0" 200 OK
ERROR:apps.ollama.main:Connection error: Cannot connect to host jayinchinalocal.com:11434 ssl:default [Name or service not known]

The IP is actually the one from the hosts file but for some reason it can't find it the hostname?

ping somedomain.com
PING somedomain.com (192.168.2.108) 56(84) bytes of data.

64 bytes from somedo127.0.1.1 (192.168.2.108): icmp_seq=1 ttl=128 time=1.02 ms

I'm guessing the somedo in the return is some kind of internal hostname but hardly has anything to do with the issue.

Ollama is on another Windows machine than my server calling the queries from Linux.

OS

Linux, Docker

GPU

Nvidia

CPU

Intel

Ollama version

0.2.8

Originally created by @JayCroghan on GitHub (Jul 23, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/5879 ### What is the issue? I am trying to set a hostname in /etc/hosts and it works fine for ping but ollama gives the following output: somedomain.com below most definitely does not exist. ``` ___ __ __ _ _ _ ___ / _ \ _ __ ___ _ __ \ \ / /__| |__ | | | |_ _| | | | | '_ \ / _ \ '_ \ \ \ /\ / / _ \ '_ \| | | || | | |_| | |_) | __/ | | | \ V V / __/ |_) | |_| || | \___/| .__/ \___|_| |_| \_/\_/ \___|_.__/ \___/|___| |_| v0.3.6 - building the best open-source AI user interface. https://github.com/open-webui/open-webui INFO:apps.openai.main:get_all_models() INFO:apps.ollama.main:get_all_models() ERROR:apps.ollama.main:Connection error: Cannot connect to host somedomain.com:11434 ssl:default [Name or service not known] INFO: 192.168.2.108:0 - "GET /ws/socket.io/?EIO=4&transport=polling&t=P3W7LDd HTTP/1.0" 200 OK INFO:apps.openai.main:get_all_models() INFO:apps.ollama.main:get_all_models() ERROR:apps.ollama.main:Connection error: Cannot connect to host somedomain.com:11434 ssl:default [Name or service not known] INFO: 192.168.2.108:0 - "POST /ws/socket.io/?EIO=4&transport=polling&t=P3W7LZz&sid=qzoO8V8hGw4XAjT7AAAA HTTP/1.0" 200 OK INFO:apps.openai.main:get_all_models() INFO:apps.ollama.main:get_all_models() INFO:apps.openai.main:get_all_models() INFO:apps.ollama.main:get_all_models() ERROR:apps.ollama.main:Connection error: Cannot connect to host somedomain.com:11434 ssl:default [Name or service not known] INFO: 192.168.2.108:0 - "GET /ws/socket.io/?EIO=4&transport=websocket&sid=qzoO8V8hGw4XAjT7AAAA HTTP/1.0" 200 OK ERROR:apps.ollama.main:Connection error: Cannot connect to host jayinchinalocal.com:11434 ssl:default [Name or service not known] ``` The IP is actually the one from the hosts file but for some reason it can't find it the hostname? ``` ping somedomain.com PING somedomain.com (192.168.2.108) 56(84) bytes of data. 64 bytes from somedo127.0.1.1 (192.168.2.108): icmp_seq=1 ttl=128 time=1.02 ms ``` I'm guessing the somedo in the return is some kind of internal hostname but hardly has anything to do with the issue. Ollama is on another Windows machine than my server calling the queries from Linux. ### OS Linux, Docker ### GPU Nvidia ### CPU Intel ### Ollama version 0.2.8
GiteaMirror added the bug label 2026-04-28 14:33:28 -05:00
Author
Owner

@rick-github commented on GitHub (Jul 23, 2024):

This doesn't look like an ollama issue.

Are you editing /etc/hosts in the docker container or on the host system?

<!-- gh-comment-id:2245548965 --> @rick-github commented on GitHub (Jul 23, 2024): This doesn't look like an ollama issue. Are you editing /etc/hosts in the docker container or on the host system?
Author
Owner

@JayCroghan commented on GitHub (Jul 23, 2024):

This is entirely a brain fart, you are right, I am not. But I will need to edit the file once the container is running, is there a way to do that? OR edit the extra_hosts in my compse file.

<!-- gh-comment-id:2245555531 --> @JayCroghan commented on GitHub (Jul 23, 2024): This is entirely a brain fart, you are right, I am not. But I will need to edit the file once the container is running, is there a way to do that? OR edit the extra_hosts in my compse file.
Author
Owner

@rick-github commented on GitHub (Jul 23, 2024):

Is the IP address dynamic or static?

One approach would to take a copy of the /etc/hosts from the open-webui container, edit it as required, and mount it during start as an additional volume in your docker-compose.yaml:

services:
  ollama:
#...
  open-webui:
#...
    volumes:
      - ./hosts:/etc/hosts
<!-- gh-comment-id:2245571181 --> @rick-github commented on GitHub (Jul 23, 2024): Is the IP address dynamic or static? One approach would to take a copy of the /etc/hosts from the open-webui container, edit it as required, and mount it during start as an additional `volume` in your docker-compose.yaml: ```yaml services: ollama: #... open-webui: #... volumes: - ./hosts:/etc/hosts ```
Author
Owner

@JayCroghan commented on GitHub (Jul 23, 2024):

It's dynamic, I wrote an API to take the dynamic IP from the host that writes to my local file. I could just docker cp that across to my container but they are different.

In your example, adding it a volume, that still doesn't allow me to edit it without copying it to the host, editing it and copying it back.

<!-- gh-comment-id:2245597372 --> @JayCroghan commented on GitHub (Jul 23, 2024): It's dynamic, I wrote an API to take the dynamic IP from the host that writes to my local file. I could just docker cp that across to my container but they are different. In your example, adding it a volume, that still doesn't allow me to edit it without copying it to the host, editing it and copying it back.
Author
Owner

@rick-github commented on GitHub (Jul 23, 2024):

In your docker-compose.yaml:

services:
  open-webui:
#...
    extra_hosts:
      - ${OLLAMA_HOST-somedomain.com:127.0.0.1}

When you start the open-webui service:

$ export OLLAMA_HOST=somedomain.com:$(script-that-gets-the-ip-address-of-the-ollama-server)
$ docker compose up -d open-webui
<!-- gh-comment-id:2245681843 --> @rick-github commented on GitHub (Jul 23, 2024): In your docker-compose.yaml: ```yaml services: open-webui: #... extra_hosts: - ${OLLAMA_HOST-somedomain.com:127.0.0.1} ``` When you start the open-webui service: ```sh $ export OLLAMA_HOST=somedomain.com:$(script-that-gets-the-ip-address-of-the-ollama-server) $ docker compose up -d open-webui ```
Author
Owner

@JayCroghan commented on GitHub (Jul 23, 2024):

Ok, I can do that much easier than the server I was using to write to the hosts file and skip hosts file completely.

Can I skip compose and just use that EXPORT for docker run or that's a no no with docker?? Sorry I'm new with docker.

Thanks!

<!-- gh-comment-id:2245763319 --> @JayCroghan commented on GitHub (Jul 23, 2024): Ok, I can do that much easier than the server I was using to write to the hosts file and skip hosts file completely. Can I skip compose and just use that EXPORT for docker run or that's a no no with docker?? Sorry I'm new with docker. Thanks!
Author
Owner

@JayCroghan commented on GitHub (Jul 23, 2024):

Or I can make my script copy the file into the container anytime a change is made I guess.

<!-- gh-comment-id:2245764884 --> @JayCroghan commented on GitHub (Jul 23, 2024): Or I can make my script copy the file into the container anytime a change is made I guess.
Author
Owner

@rick-github commented on GitHub (Jul 23, 2024):

If you're not using docker compose then you can just slightly modify the example of how to run it from the open-webui documentation. Forget about messing around with somedomain.com, point directly to the ollama server:

docker run -d -p 3000:8080 -e OLLAMA_BASE_URL=http://$(script-that-gets-the-ip-address-of-the-ollama-server) -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main
<!-- gh-comment-id:2245775338 --> @rick-github commented on GitHub (Jul 23, 2024): If you're not using docker compose then you can just slightly modify the example of how to run it from the open-webui documentation. Forget about messing around with somedomain.com, point directly to the ollama server: ```sh docker run -d -p 3000:8080 -e OLLAMA_BASE_URL=http://$(script-that-gets-the-ip-address-of-the-ollama-server) -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main ```
Author
Owner

@JayCroghan commented on GitHub (Jul 23, 2024):

And that will run the script on the host and not in the container?

On Wed 24 Jul 2024 at 01:04, frob @.***> wrote:

If you're not using docker compose then you can just slightly modify the
example of how to run if from the open-webui documentation. Forget about
messing around with somedomain.com, point directly to the ollama server:

docker run -d -p 3000:8080 -e OLLAMA_BASE_URL=http://$(script-that-gets-the-ip-address-of-the-ollama-server) -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main


Reply to this email directly, view it on GitHub
https://github.com/ollama/ollama/issues/5879#issuecomment-2245775338,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAI55TEDTJWFO3IO5R7ELIDZN2EJBAVCNFSM6AAAAABLKUOYHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBVG43TKMZTHA
.
You are receiving this because you authored the thread.Message ID:
@.***>

<!-- gh-comment-id:2245780728 --> @JayCroghan commented on GitHub (Jul 23, 2024): And that will run the script on the host and not in the container? On Wed 24 Jul 2024 at 01:04, frob ***@***.***> wrote: > If you're not using docker compose then you can just slightly modify the > example of how to run if from the open-webui documentation. Forget about > messing around with somedomain.com, point directly to the ollama server: > > docker run -d -p 3000:8080 -e OLLAMA_BASE_URL=http://$(script-that-gets-the-ip-address-of-the-ollama-server) -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main > > — > Reply to this email directly, view it on GitHub > <https://github.com/ollama/ollama/issues/5879#issuecomment-2245775338>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAI55TEDTJWFO3IO5R7ELIDZN2EJBAVCNFSM6AAAAABLKUOYHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBVG43TKMZTHA> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@rick-github commented on GitHub (Jul 23, 2024):

Yes, $(cmd) will be executed on the host, the contents will be put in the environment variable OLLAMA_BASE_URL, and open-webui inside the container will use that when trying to connect to the ollama server.

<!-- gh-comment-id:2245787107 --> @rick-github commented on GitHub (Jul 23, 2024): Yes, `$(cmd)` will be executed on the host, the contents will be put in the environment variable `OLLAMA_BASE_URL`, and open-webui inside the container will use that when trying to connect to the ollama server.
Author
Owner

@JayCroghan commented on GitHub (Jul 23, 2024):

Thank you so much that is superb.

On Wed 24 Jul 2024 at 01:08, frob @.***> wrote:

Yes, $(cmd) will be executed on the host, the contents will be put in the
environment variable OLLAMA_BASE_URL, and open-webui inside the container
will use that when trying to connect to the ollama server.


Reply to this email directly, view it on GitHub
https://github.com/ollama/ollama/issues/5879#issuecomment-2245787107,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAI55TANNBJVN3PL43LBFDLZN2EXZAVCNFSM6AAAAABLKUOYHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBVG44DOMJQG4
.
You are receiving this because you authored the thread.Message ID:
@.***>

<!-- gh-comment-id:2245793310 --> @JayCroghan commented on GitHub (Jul 23, 2024): Thank you so much that is superb. On Wed 24 Jul 2024 at 01:08, frob ***@***.***> wrote: > Yes, $(cmd) will be executed on the host, the contents will be put in the > environment variable OLLAMA_BASE_URL, and open-webui inside the container > will use that when trying to connect to the ollama server. > > — > Reply to this email directly, view it on GitHub > <https://github.com/ollama/ollama/issues/5879#issuecomment-2245787107>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAI55TANNBJVN3PL43LBFDLZN2EXZAVCNFSM6AAAAABLKUOYHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBVG44DOMJQG4> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@JayCroghan commented on GitHub (Jul 24, 2024):

For my specific problem it was a lot easier actually, the top answer here worked. I just add .local to the end of the windows hostname and it works fine!

https://askubuntu.com/questions/266265/access-windows-machines-from-ubuntu-on-local-network-by-hostname

<!-- gh-comment-id:2248651585 --> @JayCroghan commented on GitHub (Jul 24, 2024): For my specific problem it was a lot easier actually, the top answer here worked. I just add .local to the end of the windows hostname and it works fine! https://askubuntu.com/questions/266265/access-windows-machines-from-ubuntu-on-local-network-by-hostname
Author
Owner

@technovangelist commented on GitHub (Jul 25, 2024):

Can you go ahead and close the issue. And try to only add the bug label when it is a bug.

<!-- gh-comment-id:2250827415 --> @technovangelist commented on GitHub (Jul 25, 2024): Can you go ahead and close the issue. And try to only add the bug label when it is a bug.
Author
Owner

@JayCroghan commented on GitHub (Jul 25, 2024):

Yes, $(cmd) will be executed on the host, the contents will be put in the environment variable OLLAMA_BASE_URL, and open-webui inside the container will use that when trying to connect to the ollama server.

Question though: I have '-e OLLAMA_BASE_URL=http://$(cat /home/jay/dynip/ip.txt)' in my docker run, when the IP changes, how does that change the environment variable? That was my problem from the outset was how do I tell OLLAMA that the IP has changed without taking it down...

<!-- gh-comment-id:2250908337 --> @JayCroghan commented on GitHub (Jul 25, 2024): > Yes, `$(cmd)` will be executed on the host, the contents will be put in the environment variable `OLLAMA_BASE_URL`, and open-webui inside the container will use that when trying to connect to the ollama server. Question though: I have '-e OLLAMA_BASE_URL=http://$(cat /home/jay/dynip/ip.txt)' in my docker run, when the IP changes, how does that change the environment variable? That was my problem from the outset was how do I tell OLLAMA that the IP has changed without taking it down...
Author
Owner

@rick-github commented on GitHub (Jul 25, 2024):

Yeah, during the initial discussion I meant to ask you if the IP address would change during the life of the ollama container, I forgot to follow up on that. If you are using .local, then use '-e OLLAMA_BASE_URL=http://myollamaserver.local instead. When the ollama server restarts, it will broadcast it's new WINS allocation and open-webui will resolve it and talk to the new IP address.

<!-- gh-comment-id:2250970278 --> @rick-github commented on GitHub (Jul 25, 2024): Yeah, during the initial discussion I meant to ask you if the IP address would change during the life of the ollama container, I forgot to follow up on that. If you are using `.local`, then use `'-e OLLAMA_BASE_URL=http://myollamaserver.local` instead. When the ollama server restarts, it will broadcast it's new WINS allocation and open-webui will resolve it and talk to the new IP address.
Author
Owner

@JayCroghan commented on GitHub (Jul 25, 2024):

The problem I had using .local was in the container it can’t resolve that
local so I’m resorting now to my first idea. The answer is yes the IP will
change while the container is up so how do I tell Ollama it has changed
since it started?

On Fri 26 Jul 2024 at 00:51, frob @.***> wrote:

Yeah, during the initial discussion I meant to ask you if the IP address
would change during the life of the ollama container, I forgot to follow up
on that. If you are using .local, then use '-e OLLAMA_BASE_URL=
http://myollamaserver.local instead. When the ollama server restarts, it
will broadcast it's new WINS allocation and open-webui will resolve it and
talk to the new IP address.


Reply to this email directly, view it on GitHub
https://github.com/ollama/ollama/issues/5879#issuecomment-2250970278,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAI55TDDPWNX2KTASSIR3S3ZOEUHZAVCNFSM6AAAAABLKUOYHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJQHE3TAMRXHA
.
You are receiving this because you modified the open/close state.Message
ID: @.***>

<!-- gh-comment-id:2250975085 --> @JayCroghan commented on GitHub (Jul 25, 2024): The problem I had using .local was in the container it can’t resolve that local so I’m resorting now to my first idea. The answer is yes the IP will change while the container is up so how do I tell Ollama it has changed since it started? On Fri 26 Jul 2024 at 00:51, frob ***@***.***> wrote: > Yeah, during the initial discussion I meant to ask you if the IP address > would change during the life of the ollama container, I forgot to follow up > on that. If you are using .local, then use '-e OLLAMA_BASE_URL= > http://myollamaserver.local instead. When the ollama server restarts, it > will broadcast it's new WINS allocation and open-webui will resolve it and > talk to the new IP address. > > — > Reply to this email directly, view it on GitHub > <https://github.com/ollama/ollama/issues/5879#issuecomment-2250970278>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAI55TDDPWNX2KTASSIR3S3ZOEUHZAVCNFSM6AAAAABLKUOYHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJQHE3TAMRXHA> > . > You are receiving this because you modified the open/close state.Message > ID: ***@***.***> >
Author
Owner

@JayCroghan commented on GitHub (Jul 25, 2024):

Adding the following resulted in the same issue, except the ports don't change as normal because of network host

-e OLLAMA_BASE_URL=http://desktop-jay.local:11434 -v /etc/nsswitch.conf:/etc/nsswitch.conf -v open-webui:/app/backend/data -d --network host

Maybe because it doesn't know what wins is?

<!-- gh-comment-id:2250992484 --> @JayCroghan commented on GitHub (Jul 25, 2024): Adding the following resulted in the same issue, except the ports don't change as normal because of `network host` `-e OLLAMA_BASE_URL=http://desktop-jay.local:11434 -v /etc/nsswitch.conf:/etc/nsswitch.conf -v open-webui:/app/backend/data -d --network host` Maybe because it doesn't know what wins is?
Author
Owner

@rick-github commented on GitHub (Jul 25, 2024):

Did you install winbind in the open-webui container? If not, then adding wins to the hosts won't work.

<!-- gh-comment-id:2251009392 --> @rick-github commented on GitHub (Jul 25, 2024): Did you install `winbind` in the open-webui container? If not, then adding `wins` to the `hosts` won't work.
Author
Owner

@JayCroghan commented on GitHub (Jul 25, 2024):

Did you install winbind in the open-webui container? If not, then adding wins to the hosts won't work.

No I'm using ghcr.io/open-webui/open-webui:main so I can't change the docker file and yes that's why wins won't work and why I'm resorting to changing the IP at runtime. ENV variable won't work as that's only checked at runtime.

<!-- gh-comment-id:2251011484 --> @JayCroghan commented on GitHub (Jul 25, 2024): > Did you install `winbind` in the open-webui container? If not, then adding `wins` to the `hosts` won't work. No I'm using ghcr.io/open-webui/open-webui:main so I can't change the docker file and yes that's why wins won't work and why I'm resorting to changing the IP at runtime. ENV variable won't work as that's only checked at runtime.
Author
Owner

@rick-github commented on GitHub (Jul 25, 2024):

If you don't want to modify the container, you'll have to do the resolution on the host. There are a number of ways to do this, none of them pretty.

Are the windows and linux hosts on the same network? Are the ip addresses in a public or private (192.168, 172., etc) space? If private, do you have access to the device that does the dynamic IP address allocation? Does yout linux server currently run a DNS server? Can you add services to the windows machine?

BTW, this would be simpler if both services ran on the same machine, is the separation a requirement?

<!-- gh-comment-id:2251096065 --> @rick-github commented on GitHub (Jul 25, 2024): If you don't want to modify the container, you'll have to do the resolution on the host. There are a number of ways to do this, none of them pretty. Are the windows and linux hosts on the same network? Are the ip addresses in a public or private (192.168, 172., etc) space? If private, do you have access to the device that does the dynamic IP address allocation? Does yout linux server currently run a DNS server? Can you add services to the windows machine? BTW, this would be simpler if both services ran on the same machine, is the separation a requirement?
Author
Owner

@JayCroghan commented on GitHub (Jul 25, 2024):

They need to be different, my web server(s) are all on one box and the machine with the RTX GPU is on another. They're on the same network but due to the solution below it doesn't matter the GPU machine will update the OpenUI machine anytime the IP changes.

As I said before, I already wrote an app on the windows machine that calls a service I wrote that runs on the OpenWebUI machine anytime the IP changes. I have it currently setting an entry in the /etc/hosts file and writing to a text file. I just need some way of telling the running container the new address of the OLLAMA_BASE_URL at runtime because nothing I change on the host will change what's in the container.

I can get the IP on the OpenWebUI host already, my problem is setting it and telling Ollama it has been updated on the container at runtime. Whether that is via a script I copy over or what not.

My very last of the line solution if there is no other way was to update a hosts file on the host machine and copying it across to the container anytime the IP changes using docker cp

<!-- gh-comment-id:2251212645 --> @JayCroghan commented on GitHub (Jul 25, 2024): They need to be different, my web server(s) are all on one box and the machine with the RTX GPU is on another. They're on the same network but due to the solution below it doesn't matter the GPU machine will update the OpenUI machine anytime the IP changes. As I said before, I already wrote an app on the windows machine that calls a service I wrote that runs on the OpenWebUI machine anytime the IP changes. I have it currently setting an entry in the /etc/hosts file and writing to a text file. I just need some way of telling the running container the new address of the OLLAMA_BASE_URL at runtime because nothing I change on the host will change what's in the container. I can get the IP on the OpenWebUI host already, my problem is setting it and telling Ollama it has been updated on the container at runtime. Whether that is via a script I copy over or what not. My very last of the line solution if there is no other way was to update a hosts file on the host machine and copying it across to the container anytime the IP changes using `docker cp`
Author
Owner

@rick-github commented on GitHub (Jul 25, 2024):

Get a copy of the hosts file from the open-webui image:

docker run -it --rm --entrypoint bash ghcr.io/open-webui/open-webui -c 'cat /etc/hosts' > hosts

Add a place holder to it:

echo "127.0.0.1 ollama" >> hosts

Run your open-webui, mounting the hosts file and setting OLLAMA_BASE_URL:

docker run -d -p 3000:8080 \
    -e OLLAMA_BASE_URL=http://ollama:11434 \
    -v ./hosts:/etc/hosts \
    -v open-webui:/app/backend/data \
    --name open-webui \
    --restart always \
    ghcr.io/open-webui/open-webui:main

When the windows box calls the service on the OpenWebUI machine to notify an IP change, have it update the ollama line in the hosts file, eg:

file=/path/to/hosts ; hosts=$(cat $file) ; echo "$hosts" | sed -e "s/^[0-9.]* ollama$/$NEW_IP_ADDRESS ollama/" > $file

Note that you must use an update method that doesn't change the inode of the file, perl -pi -e won't work.

Also note that you may have state saved in the open-webui volume that already set the ollama endpoint and setting OLLAMA_BASE_URL may not override it. You can either go to the admin panel in open-webui and set it to http://ollama:11434, or remove the open-webui volume and start from scratch: docker volume rm open-webui.

<!-- gh-comment-id:2251333272 --> @rick-github commented on GitHub (Jul 25, 2024): Get a copy of the hosts file from the open-webui image: ``` docker run -it --rm --entrypoint bash ghcr.io/open-webui/open-webui -c 'cat /etc/hosts' > hosts ``` Add a place holder to it: ``` echo "127.0.0.1 ollama" >> hosts ``` Run your open-webui, mounting the hosts file and setting OLLAMA_BASE_URL: ``` docker run -d -p 3000:8080 \ -e OLLAMA_BASE_URL=http://ollama:11434 \ -v ./hosts:/etc/hosts \ -v open-webui:/app/backend/data \ --name open-webui \ --restart always \ ghcr.io/open-webui/open-webui:main ``` When the windows box calls the service on the OpenWebUI machine to notify an IP change, have it update the `ollama` line in the hosts file, eg: ``` file=/path/to/hosts ; hosts=$(cat $file) ; echo "$hosts" | sed -e "s/^[0-9.]* ollama$/$NEW_IP_ADDRESS ollama/" > $file ``` Note that you must use an update method that doesn't change the inode of the file, `perl -pi -e` won't work. Also note that you may have state saved in the open-webui volume that already set the ollama endpoint and setting OLLAMA_BASE_URL may not override it. You can either go to the admin panel in open-webui and set it to http://ollama:11434, or remove the open-webui volume and start from scratch: `docker volume rm open-webui`.
Author
Owner

@JayCroghan commented on GitHub (Jul 26, 2024):

Thanks very much for this, it gives me plenty to think about and play with. It's really hard to imagine why there is no way to programmatically tell Ollama the host is updated.

You can either go to the admin panel in open-webui and set it to http://ollama:11434, or remove the open-webui volume and start from scratch: docker volume rm open-webui.

The input box for the URI is always greyed out for me on the models page, otherwise I wouldn't need this solution!!

<!-- gh-comment-id:2251995007 --> @JayCroghan commented on GitHub (Jul 26, 2024): Thanks very much for this, it gives me plenty to think about and play with. It's really hard to imagine why there is no way to programmatically tell Ollama the host is updated. >You can either go to the admin panel in open-webui and set it to http://ollama:11434, or remove the open-webui volume and start from scratch: `docker volume rm open-webui`. The input box for the URI is _always_ greyed out for me on the models page, otherwise I wouldn't need this solution!!
Author
Owner

@JayCroghan commented on GitHub (Jul 28, 2024):

Get a copy of the hosts file from the open-webui image:

docker run -it --rm --entrypoint bash ghcr.io/open-webui/open-webui -c 'cat /etc/hosts' > hosts

Add a place holder to it:

echo "127.0.0.1 ollama" >> hosts

Run your open-webui, mounting the hosts file and setting OLLAMA_BASE_URL:

docker run -d -p 3000:8080 \
    -e OLLAMA_BASE_URL=http://ollama:11434 \
    -v ./hosts:/etc/hosts \
    -v open-webui:/app/backend/data \
    --name open-webui \
    --restart always \
    ghcr.io/open-webui/open-webui:main

When the windows box calls the service on the OpenWebUI machine to notify an IP change, have it update the ollama line in the hosts file, eg:

file=/path/to/hosts ; hosts=$(cat $file) ; echo "$hosts" | sed -e "s/^[0-9.]* ollama$/$NEW_IP_ADDRESS ollama/" > $file

Note that you must use an update method that doesn't change the inode of the file, perl -pi -e won't work.

Also note that you may have state saved in the open-webui volume that already set the ollama endpoint and setting OLLAMA_BASE_URL may not override it. You can either go to the admin panel in open-webui and set it to http://ollama:11434, or remove the open-webui volume and start from scratch: docker volume rm open-webui.

IT WORKS!!!! I'm using an edited npm package called Hostile to edit the hosts file with -v /home/jay/dynip/hosts:/etc/hosts in my docker run and it updates automatically when I call my webserver to update it. Thanks so much!

<!-- gh-comment-id:2254460971 --> @JayCroghan commented on GitHub (Jul 28, 2024): > Get a copy of the hosts file from the open-webui image: > > ``` > docker run -it --rm --entrypoint bash ghcr.io/open-webui/open-webui -c 'cat /etc/hosts' > hosts > ``` > > Add a place holder to it: > > ``` > echo "127.0.0.1 ollama" >> hosts > ``` > > Run your open-webui, mounting the hosts file and setting OLLAMA_BASE_URL: > > ``` > docker run -d -p 3000:8080 \ > -e OLLAMA_BASE_URL=http://ollama:11434 \ > -v ./hosts:/etc/hosts \ > -v open-webui:/app/backend/data \ > --name open-webui \ > --restart always \ > ghcr.io/open-webui/open-webui:main > ``` > > When the windows box calls the service on the OpenWebUI machine to notify an IP change, have it update the `ollama` line in the hosts file, eg: > > ``` > file=/path/to/hosts ; hosts=$(cat $file) ; echo "$hosts" | sed -e "s/^[0-9.]* ollama$/$NEW_IP_ADDRESS ollama/" > $file > ``` > > Note that you must use an update method that doesn't change the inode of the file, `perl -pi -e` won't work. > > Also note that you may have state saved in the open-webui volume that already set the ollama endpoint and setting OLLAMA_BASE_URL may not override it. You can either go to the admin panel in open-webui and set it to http://ollama:11434, or remove the open-webui volume and start from scratch: `docker volume rm open-webui`. IT WORKS!!!! I'm using an edited npm package called Hostile to edit the hosts file with `-v /home/jay/dynip/hosts:/etc/hosts` in my `docker run` and it updates automatically when I call my webserver to update it. Thanks so much!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#50179