Buy @ Amazon

Connect to Ollama in Windows host from Docker container


It is one things to connect to services running in Docker container from Window host and altogether another thing to do the reverse of it. Attempting to connect to Ollama in Windows host from Docker container is that just and this post is a recipe to solve this problem.

To connect a Docker container to an Ollama instance running natively on a Windows host, you must address two main hurdles: allowing the Windows service to accept external (non-local) traffic and using the correct address from within Docker.

1. Configure Ollama to Listen on All Interfaces 

By default, Ollama service running in Windows host only listens on 127.0.0.1, which prevents Docker containers from reaching it. You will have to change it to 0.0.0.0 to get it working and to do so follow the below steps:
  • Quit Ollama service that is currently running.
  • Set Environment Variable in your Windows: OLLAMA_HOST=0.0.0.0
  • Restart Ollama service.

2. Connect from Docker using the Special DNS Name 

Docker Desktop for Windows provides a special internal DNS name that resolves to the host machine's IP address.
  • Connection URL: Use `http://host.docker.internal:11434` instead of localhost or 127.0.0.1.
  • Connection Test: From inside your docker container terminal run `curl http://host.docker.internal:11434/api/tags | jq -r '.models[].name` and you should see a list of all models available for use with your Ollama service on your Windows host.

3. Additional Reading