ECONNREFUSEDAI tool

Fix Ollama Connection Refused (Errno 111) in AutoGPT Docker

Error message

Connection Refused ([Errno 111]) When Using Ollama with AutoGPT
error-fix6 min readVerified Jul 19, 2026

Diagnosis

The error [Errno 111] Connection refused when using Ollama with AutoGPT means that AutoGPT, running inside a Docker container, cannot reach the Ollama service. The most common cause is that AutoGPT is trying to connect to localhost:11434, but inside the Docker container, localhost refers to the container itself, not the host machine where Ollama is running. This error appears even when Ollama is confirmed to be running on the host at the correct port.

What Causes This Error

1. Docker Network Namespace Isolation

Docker containers have their own network namespace. When a process inside a container tries to connect to localhost (127.0.0.1), it attempts to reach the container's own loopback interface, not the host's. Since Ollama is running on the host machine (not inside the container), the connection is refused. This is the root cause described in the accepted Stack Overflow answer by efremidze.

2. Incorrect Host Address Configuration

Even if you have verified that Ollama is running on the host at http://localhost:11434/ (using curl from the host terminal), AutoGPT's configuration must point to an address that is reachable from within the Docker container. Using localhost in the AutoGPT configuration will always fail when AutoGPT is containerized.

3. Port Mismatch (Less Common)

While the error message suggests checking the port, the default Ollama port is 11434, and the sources confirm this is correct. However, if you have changed Ollama's port or if another service is occupying port 11434, a different error would occur. The sources do not indicate a port mismatch as the cause here.

How to Fix It

Solution 1: Use host.docker.internal (Recommended)

This is the accepted solution from the Stack Overflow answer by efremidze. The host.docker.internal hostname is a special DNS name that Docker provides to allow containers to access services running on the host machine. It works on Docker Desktop for Windows, macOS, and Linux (with some configuration).

Steps:

  1. Locate the configuration file where AutoGPT stores the Ollama endpoint. This is typically in a .env file or a configuration YAML/JSON file. Common locations include:

    • autogpt/.env
    • AutoGPT/.env
    • A configuration section in docker-compose.yml
  2. Change the Ollama host from localhost to host.docker.internal. For example, if your configuration has:

    OLLAMA_HOST=http://localhost:11434
    

    Change it to:

    OLLAMA_HOST=http://host.docker.internal:11434
    
  3. Save the file and restart the AutoGPT container:

    docker-compose down
    docker-compose up -d
    
  4. Verify the connection. AutoGPT should now be able to reach Ollama. You can test connectivity from inside the container using:

    docker exec -it <autogpt_container_name> curl http://host.docker.internal:11434/
    

    Expected output: Ollama is running

Why this works: The host.docker.internal hostname resolves to the host machine's IP address from within the container, bypassing the container's loopback interface. This is documented in Docker's networking documentation and confirmed by the accepted answer.

Caveats:

  • On Linux, host.docker.internal is not available by default in Docker Engine. You may need to add --add-host host.docker.internal:host-gateway to your Docker run command or in the docker-compose.yml under extra_hosts:
    services:
      autogpt:
        extra_hosts:
          - "host.docker.internal:host-gateway"
    
  • If you are using Docker Desktop on Windows or macOS, host.docker.internal works out of the box.

Solution 2: Use the Host's IP Address Directly

If host.docker.internal does not work (e.g., on some Linux configurations), you can use the host machine's actual IP address on the Docker network.

Steps:

  1. Find the host's IP address that is reachable from the Docker container. On the host machine, run:

    ip addr show docker0 | grep inet
    

    This typically shows an IP like 172.17.0.1. Alternatively, use the host's local network IP (e.g., 192.168.x.x).

  2. Update the AutoGPT configuration to use that IP:

    OLLAMA_HOST=http://172.17.0.1:11434
    
  3. Restart the container as in Solution 1.

Why this works: The Docker bridge network allows containers to communicate with the host via the gateway IP (usually 172.17.0.1). This is a more manual but reliable method.

Caveats:

  • The IP address may change if Docker is restarted or if the network configuration changes. This makes it less stable than host.docker.internal.
  • You must ensure that Ollama is listening on all interfaces (not just localhost). By default, Ollama listens on 127.0.0.1:11434. To allow external connections, you may need to start Ollama with:
    OLLAMA_HOST=0.0.0.0:11434 ollama serve
    
    Or set the environment variable OLLAMA_HOST=0.0.0.0 in your Ollama service configuration.

Solution 3: Run AutoGPT Without Docker (Workaround)

If the Docker networking issues persist, you can run AutoGPT directly on the host machine (not in a container). This eliminates the network namespace problem entirely.

Steps:

  1. Ensure Python 3.10+ and pip are installed on the host.
  2. Clone the AutoGPT repository and install dependencies:
    git clone https://github.com/Significant-Gravitas/AutoGPT.git
    cd AutoGPT
    pip install -r requirements.txt
    
  3. Set the Ollama host to localhost:
    OLLAMA_HOST=http://localhost:11434
    
  4. Run AutoGPT:
    python -m autogpt
    

Why this works: Running on the host means localhost correctly refers to the host machine, so Ollama is reachable.

Caveats:

  • This bypasses Docker's isolation and reproducibility benefits.
  • You must manage dependencies and environment manually.

If Nothing Works

If none of the above solutions resolve the error, consider the following escalation paths:

  1. Check the GitHub issue referenced in the accepted answer: The solution is discussed in Ollama Issue #703. Review the issue for additional workarounds or updates.

  2. Verify Ollama is listening on all interfaces: Run netstat -tuln | grep 11434 on the host. If it shows 127.0.0.1:11434, Ollama is only listening locally. Change the OLLAMA_HOST environment variable to 0.0.0.0:11434 and restart Ollama.

  3. Check Docker Compose network configuration: Ensure both AutoGPT and Ollama are on the same Docker network. If Ollama is also running in a container, use service names instead of IP addresses.

  4. Post a new question on Stack Overflow with your Docker Compose file, AutoGPT configuration, and the exact error output. Include the output of docker network inspect and docker logs <autogpt_container>.

  5. File an issue on the AutoGPT GitHub repository if you believe it is a bug in AutoGPT's Docker configuration.

How to Prevent It

To avoid this error in the future:

  • Always use host.docker.internal when configuring a Docker container to connect to a service running on the host. This is the standard Docker pattern for host-to-container communication.
  • Document your Docker Compose setup with explicit extra_hosts entries if using Linux:
    services:
      autogpt:
        extra_hosts:
          - "host.docker.internal:host-gateway"
    
  • Test connectivity from inside the container before relying on AutoGPT. Use docker exec with curl to verify the endpoint is reachable.
  • Keep Ollama and AutoGPT updated to the latest versions, as networking fixes may be included in updates.
  • Use environment variables for the Ollama host URL so it can be easily changed without modifying code.

By following these practices, you can ensure that AutoGPT and Ollama communicate reliably, even in complex Docker environments.

Was this helpful?
Newsletter

The #1 AI Newsletter

The most important ai updates, guides, and fixes โ€” one weekly email.

No spam, unsubscribe anytime. Privacy policy

Sources & References

This page was researched from 2 independent sources, combined and verified for completeness.

Related Error Solutions

Keep exploring

Skip the manual work

Ready-made AI workflows and automation templates โ€” import and run instead of building from scratch.

Explore workflows