Skip to content
FR
  1. LuzineDebug
  2. AI & LLMs
  3. Error: could not connect to ollama app, is it ru…
AI & LLMs Beginner ≈ 10 min to fix

Fix "could not connect to ollama" and connection refused on port 11434

Error message
Error: could not connect to ollama app, is it running?
  • ConnectionError: Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. https://ollama.com/download
  • requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('Failed to establish a new connection: [Errno 111] Connection refused'))
  • TypeError: fetch failed [cause]: Error: connect ECONNREFUSED 127.0.0.1:11434
  • Error: connect ECONNREFUSED ::1:11434
In short

The client (the ollama command, your script or your app) cannot reach the Ollama server on 127.0.0.1:11434. Start the server (Ollama app, systemctl start ollama or ollama serve), check with curl http://127.0.0.1:11434, then make sure the client targets the right address: from Docker it is not localhost but host.docker.internal or the service name.

Be the first to confirm this fix

What this error means

Ollama works in two parts: a server that loads models and exposes an HTTP API, by default on 127.0.0.1:11434, and clients (ollama run CLI, Python or JavaScript libraries, LangChain, Open WebUI…) that send requests to that address. “Connection refused” means nothing is listening at the target address and port: either the server is not running, or it listens elsewhere, or the client uses the wrong host. This is very common inside a Docker container, where localhost means the container itself and not your machine, and with Node.js, where localhost can resolve to ::1 (IPv6) while Ollama only listens on IPv4.

Common causes

  1. Ollama server stopped: app not started on macOS or Windows, ollama service stopped or crashed on Linux, or ollama serve closed along with its terminal.
  2. Client inside a Docker container: http://localhost:11434 targets the container, not the host running Ollama.
  3. Ollama listens on loopback only: by default it listens on 127.0.0.1, so another machine, a VM or a Linux container cannot reach it.
  4. Wrong address on the client side: an OLLAMA_HOST variable pointing elsewhere, a changed port, or localhost resolved to IPv6 ::1 by Node.js.

Step-by-step fix

  1. Check whether the server answers

    Query the API directly. An “Ollama is running” reply proves the server works: the problem is then on the client side. A connection error confirms the server is not running at that address.

    bash
    curl http://127.0.0.1:11434
    # Ollama is running
    
    curl http://127.0.0.1:11434/api/tags
  2. Start Ollama

    On macOS and Windows, launch the Ollama app (icon in the menu bar or the notification area). On Linux, the installer creates a systemd service: start it and read its logs if it stops. You can also run the server in the foreground with ollama serve.

    bash
    # Linux (systemd service)
    sudo systemctl start ollama
    systemctl status ollama
    journalctl -u ollama -e
    
    # any OS, in the foreground
    ollama serve
  3. Point the client to the right address

    Use 127.0.0.1 instead of localhost to avoid Node.js resolving to IPv6. The CLI and the Python library read the OLLAMA_HOST variable; you can also pass the host explicitly. For the OpenAI-compatible API, the base URL is http://127.0.0.1:11434/v1.

    python
    from ollama import Client
    
    client = Client(host="http://127.0.0.1:11434")
    response = client.chat(
        model="llama3.2",
        messages=[{"role": "user", "content": "Hello"}],
    )
    print(response.message.content)
  4. From Docker: target the host or a service

    If Ollama runs on the host machine, use http://host.docker.internal:11434 (automatic with Docker Desktop; on Linux, add extra_hosts). The simplest option is often to run Ollama as a service in the same compose.yaml and call it by name, without publishing the port.

    yaml
    services:
      app:
        build: .
        environment:
          OLLAMA_HOST: http://ollama:11434
        depends_on:
          - ollama
    
      ollama:
        image: ollama/ollama
        volumes:
          - ollama:/root/.ollama
    
      # Ollama on the host instead (Linux):
      # app:
      #   environment:
      #     OLLAMA_HOST: http://host.docker.internal:11434
      #   extra_hosts:
      #     - "host.docker.internal:host-gateway"
    
    volumes:
      ollama:
  5. Make Ollama listen beyond loopback (carefully)

    For a Linux container, a VM or another machine to reach Ollama, make it listen on another interface with OLLAMA_HOST=0.0.0.0:11434. Beware: the Ollama API has no authentication. Never expose port 11434 to the Internet; restrict it to the local network with the firewall, or put an authenticated reverse proxy in front. On macOS, use launchctl setenv OLLAMA_HOST "0.0.0.0:11434" then restart the app; on Windows, set the OLLAMA_HOST user environment variable, then quit and relaunch Ollama.

    bash
    # Linux: add an override to the service
    sudo systemctl edit ollama.service
    # [Service]
    # Environment="OLLAMA_HOST=0.0.0.0:11434"
    
    sudo systemctl daemon-reload
    sudo systemctl restart ollama

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Keep the Ollama URL in an environment variable (OLLAMA_HOST) instead of hardcoding it.
  • Enable the service at boot on Linux with sudo systemctl enable ollama.
  • In Docker Compose, add a healthcheck on Ollama and wait for it to be healthy before starting the app.

Frequently asked questions

ollama serve says “address already in use”, what should I do?

The listen tcp 127.0.0.1:11434: bind: address already in use message means an Ollama server is already running (often the app or the systemd service). Do not start a second server: just use ollama run.

Why ECONNREFUSED ::1:11434 while Ollama is running?

Node.js resolved localhost to IPv6 ::1, while Ollama listens on 127.0.0.1. Replace localhost with 127.0.0.1 in the URL.

Is it risky to set OLLAMA_HOST=0.0.0.0?

Yes if the machine is reachable from the Internet: anyone could use your models and resources. Restrict access with a firewall or an authenticated reverse proxy, or connect containers through an internal Docker network.

Useful tools for this error

More AI & LLMs errors

All AI & LLMs errors →