这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@timothycarambat
Copy link
Member

@timothycarambat timothycarambat commented Dec 28, 2023

Every time a potential user of AnythingLLM uses AnythingLLM in a dockerized context there is confusion on why some external service running on localhost/loopback [LocalAi, LMStudio, Ollama, Chroma, etc] cannot connect, resulting in failed messages or other problems during use.

This is because localhost or loopback IPs resolve within the AnythingLLM container while the service they wish to connect to uses the host machine network. The full fix is to simply replace localhost or 127.0.0.1 with host.docker.internal and the container can then reach the host machine network.

This is already outlined in the Docker README as an important tag, but considering some may be pulling from remote and never consulting the README this detail gets missed nearly all the time.

This PR blocks localhost or 127.0.0.1 from being used for external services while running inside of Docker.

Hopefully, we never have to answer this question again 😵

AnythingLLM runs multiple services inside the container to support various functions so to prevent port conflicts we use a network bridge and not the host network.

@review-agent-prime
Copy link

server/utils/helpers/updateENV.js

While the function validDockerizedUrl checks if the hostname is "localhost" or "127.0.0.1", it does not check for other potential local network addresses that might not be reachable from within a Docker container. It would be beneficial to add checks for other local network addresses to ensure the URL is reachable.
Create Issue
See the diff
Checkout the fix

    function validDockerizedUrl(input = "") {
      if (process.env.ANYTHING_LLM_RUNTIME !== "docker") return null;
      try {
        const { hostname } = new URL(input);
        if (["localhost", "127.0.0.1", "0.0.0.0"].includes(hostname.toLowerCase()))
          return "Localhost, 127.0.0.1, or 0.0.0.0 origins cannot be reached from inside the AnythingLLM container. Please use host.docker.internal or a real machine ip to connect to your external service.";
        return null;
      } catch {}
      return null;
    }
git fetch origin && git checkout -b ReviewBot/The-n-yjz7qf3 origin/ReviewBot/The-n-yjz7qf3

@timothycarambat timothycarambat merged commit d748167 into master Dec 28, 2023
@timothycarambat timothycarambat deleted the docker-patch branch December 28, 2023 18:47
cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
* Prevent external service localhost question

* add 0.0.0.0 to docker-invalid URL

* clarify hint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants