AnythingLLM passes every workspace chat to the model server chosen in its LLM settings, so a server it cannot reach stops replies entirely. When AnythingLLM runs in Docker and Ollama runs as a systemd service on the same Linux host, the usual cause of an Ollama connection error is an Ollama listener that the container cannot reach.

A fresh Ollama installation listens only on the host's loopback address. Programs on the host can use it, but a container reaches the host through the Docker bridge, so its requests are refused even while Ollama answers normally in a host terminal. Setting OLLAMA_HOST in the service to the bridge address lets the container connect without opening Ollama on the host's LAN or public interfaces.

The AnythingLLM container needs a host.docker.internal name for the Linux Docker host, which Docker adds only when the container is created with a host-gateway mapping, and its Ollama Base URL should use that name. Ollama's API has no authentication, so any container on the host can use the server once it listens on the bridge. A normal reply in the workspace that failed shows the connection is restored.

Steps to fix Ollama connection errors in AnythingLLM:

  1. Find the failed reply in the AnythingLLM workspace chat.

    The connection error appears as Could not respond to message. followed by Your Ollama instance could not be reached or is not responding. AnythingLLM accepted the message but received no answer from Ollama.

  2. Check Ollama Base URL under Settings → AI Providers → LLM.

    The address for a Linux Docker host is http://host.docker.internal:11434, the server root without /v1 or another API path. Ollama Model stays at --loading available models-- while AnythingLLM cannot query that address. localhost and 127.0.0.1 point back into the AnythingLLM container, and saving http://127.0.0.1:11434 is refused with Port is not running a reachable service on loopback address from inside the AnythingLLM container. Show advanced settings reveals the field when it is collapsed.
    Related: How to set the Ollama provider in AnythingLLM

  3. Request the Ollama version from the host's loopback address.
    $ curl -fsS http://127.0.0.1:11434/api/version
    {"version":"0.40.16"}

    A version reply shows that the Ollama service is running and answers programs on the host; the number depends on the installed release. A refused connection here means the service is stopped or failing, which systemctl status ollama and the Ollama log explain before any network change.
    Related: How to manage the Ollama service

  4. Show the local address that Ollama listens on.
    $ ss -ltn 'sport = :11434'
    State  Recv-Q Send-Q Local Address:Port  Peer Address:Port
    LISTEN 0      4096       127.0.0.1:11434      0.0.0.0:*

    127.0.0.1:11434 under Local Address:Port accepts connections only from the host itself. Container traffic arrives through the Docker bridge, so this listener refuses it.

  5. Check the Ollama service environment for an OLLAMA_HOST value.
    $ systemctl show ollama --property=Environment
    Environment=PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin

    Without OLLAMA_HOST, Ollama uses its loopback default. The PATH value comes from the shell that ran the installer and can differ. An existing OLLAMA_HOST entry comes from the unit file or one of its drop-in files, which sudo systemctl cat ollama lists; that file is the place to change the address rather than adding a second value.

  6. Find the host address that host.docker.internal resolves to inside the AnythingLLM container.
    $ docker exec anythingllm getent hosts host.docker.internal
    172.17.0.1      host.docker.internal

    anythingllm is the container name. 172.17.0.1 is the host's address on the default Docker bridge, so Ollama must listen there. No output means the container was created without --add-host host.docker.internal:host-gateway; it needs recreating with that option added to its original run options and storage mounts.
    Related: docker run --add-host

  7. Request the Ollama API from inside the AnythingLLM container.
    $ docker exec anythingllm curl -fsS --connect-timeout 3 http://host.docker.internal:11434/api/version
    curl: (7) Failed to connect to host.docker.internal port 11434 after 0 ms: Couldn't connect to server

    A refused connection after the host-side request succeeded places the fault in Ollama's listen address rather than in AnythingLLM. A timeout instead suggests a host firewall dropping traffic from the Docker bridge.

  8. Open an override file for the Ollama service.

    Ollama's local API has no authentication. Anyone who can reach the address it listens on can run models and consume the server's CPU, memory and disk, and every container on this host can reach the Docker bridge address. Network access must already be limited to trusted clients. Binding 0.0.0.0 instead would also expose Ollama on the LAN and any public interface.

    $ sudo systemctl edit ollama

    The command opens /etc/systemd/system/ollama.service.d/override.conf in the default terminal editor, with the current unit shown as comments below the editable area. A non-default editor can be chosen through the SYSTEMD_EDITOR or EDITOR variable.

  9. Add the bridge address as the OLLAMA_HOST value in the editable area at the top of the file.
    [Service]
    Environment="OLLAMA_HOST=172.17.0.1:11434"

    The lines belong between ### Anything between here and the comment below will become the contents of the drop-in file and ### Edits below this comment will be discarded; anything typed below the second comment is ignored. The address is the one getent returned, and the port matches the URL saved in AnythingLLM.

  10. Close the editor with the changes saved.

    systemctl installs the file when the editor exits, reloads the unit definitions and prints Successfully installed edited file '/etc/systemd/system/ollama.service.d/override.conf'. sudo systemctl revert ollama removes this override, together with any other drop-in files for the unit, and a restart then returns Ollama to the loopback default.

  11. Restart the Ollama service to apply the new listen address.

    A restart interrupts requests in progress and unloads models from memory. Ollama stops answering on 127.0.0.1 afterwards, so host programs that use the loopback address need the bridge address instead.

    $ sudo systemctl restart ollama
  12. Confirm that Ollama now listens on the bridge address.
    $ ss -ltn 'sport = :11434'
    State  Recv-Q Send-Q Local Address:Port  Peer Address:Port
    LISTEN 0      4096      172.17.0.1:11434      0.0.0.0:*

    The ollama command on the host reads the server address from OLLAMA_HOST, for example OLLAMA_HOST=172.17.0.1:11434 ollama list. At boot, Ollama can log bind: cannot assign requested address once because Docker has not yet created the bridge; systemd restarts it a few seconds later and it listens normally. A changed Docker bridge address needs the same change in the override.

  13. Repeat the API request from the AnythingLLM container.
    $ docker exec anythingllm curl -fsS --connect-timeout 3 http://host.docker.internal:11434/api/version
    {"version":"0.40.16"}

    A version reply shows that the container now reaches Ollama through host.docker.internal.

  14. Reload the LLM settings page in AnythingLLM.
  15. Confirm that Ollama Model shows a model installed in Ollama.

    The list now comes from the Ollama server and includes models such as qwen2.5:0.5b. The saved Base URL and model need no further change. A model missing from the list must be pulled into Ollama first.
    Related: How to pull an Ollama model

  16. Send a short message in the workspace that failed.

    AnythingLLM does not keep the failed exchange, so the thread can open empty.

  17. Confirm that the workspace shows a reply from the Ollama model.

    A reply in place of Could not respond to message. shows that AnythingLLM reaches Ollama again. The first reply after the restart can pause at Loading qwen2.5:0.5b into memory, this may take a moment. while Ollama loads the model.

Share this guide