Dify reports “connection refused,” times out, or cannot find a model served by Ollama on DGX Spark.
Fastest fix: Check the address from inside the Dify container. There, localhost points to that container, not the DGX Spark host. Use a host address the container can reach, then verify Ollama’s listener, the plugin Base URL, and firewall rules. Never expose an unauthenticated Ollama port directly to the public internet.
This guide is for developers running Ollama on DGX Spark and calling it from Dify, including teams troubleshooting a RAG workflow or Agent.
It also helps technical leads decide whether Dify and the model service should share a host.
The scope is connection troubleshooting, not model installation or inference-speed testing.
Last updated: December 4, 2026. The steps below are based on the Dify Ollama integration guide, Dify Docker troubleshooting documentation, and current Ollama API documentation. Verify commands and network addresses against the deployment in use.
Start with the point where the request fails
Trace the request in order: Ollama on the DGX Spark host, the network path from the Dify container, the Dify Ollama plugin, then the app or Agent workflow. A successful request on the host proves only that Ollama is responding locally. It does not prove that a separate container can reach it.
| Symptom | Likely layer | First check |
|---|---|---|
| Connection refused | Ollama is stopped, listening on a different address, or the target port is not accepting connections | Check the listener on the host and request the same address from the Dify container |
| Connection timeout | The container cannot route to the host, or a firewall is dropping traffic | Check Docker network reachability and host firewall rules |
| Model not found | The request reached Ollama, but the selected model name does not match a loaded model | Compare the plugin’s model name with Ollama’s model list |
| Chat test works, Agent fails | The model connection works; the failure may be in tool execution, sandbox restrictions, or workflow configuration | Inspect the Agent and sandbox logs separately |
This distinction prevents a common detour: changing models or blaming DGX Spark performance when the request is simply going to the wrong address.
First check: Use an address the Dify container can reach
Why does Dify fail when its Ollama Base URL is localhost?
Because localhost is relative to the process making the request. If Dify runs in a Docker container and Ollama runs on the DGX Spark host, the container’s localhost identifies the container itself. It does not automatically identify the host.
Docker’s networking documentation describes how containers communicate across network boundaries. Dify’s Ollama integration instructions also advise using an address reachable from the container. A name such as host.docker.internal may work in some environments, but its availability depends on the Docker setup. Do not assume it is configured.
| Where the request runs | Address to test | What a successful test establishes |
|---|---|---|
| DGX Spark host | Ollama’s local address and port | Ollama responds on the host |
| Dify container | A host address reachable from that container | The container can reach the Ollama service |
| Dify model settings | The same reachable host address and port | The plugin has a usable destination |
Do not copy an address into the plugin simply because it works in a host-shell test. Test the exact candidate address from the Dify container first.
What should the Ollama Base URL be when Dify runs in Docker?
Use the root address of the Ollama service that the container can reach, with the port expected by the plugin. Follow the current Dify Marketplace Ollama plugin configuration. Do not append an API path unless the plugin documentation explicitly asks for one. A plugin may build its own request path from the Base URL.
For a self-hosted Dify deployment, check the official Docker Compose deployment instructions to identify the services and networks in that installation. Service names and container layouts can differ by deployment and version.
Second check: Confirm that Ollama is listening beyond loopback
A container cannot connect to a host service that listens only on the host’s loopback interface. On the DGX Spark host, inspect the listener:
ss -lntp | grep 11434
Ollama’s standard local API uses port 11434; confirm the expected endpoint in the Ollama API introduction. The output from ss helps distinguish a stopped service from one bound only to a loopback address or to a host-facing address.
Then test the service from the host, substituting the address used by the local installation:
curl http://127.0.0.1:11434/api/tags
Ollama documents this model-list endpoint in its API reference. If the host request fails, fix the Ollama service before changing Dify settings.
If host access works but the container cannot connect, check the listener address and host firewall. Ollama’s network access guidance explains how to expose the service beyond loopback. Any change that permits network access must be paired with firewall restrictions. Allow only the Dify host or the specific container network that needs access. Do not make the service publicly reachable for convenience.
A listener bound to a network address is not the same as a protected service. Confirm both the intended bind address and the permitted source addresses before moving on.
Third check: Test from the Dify container, not just from the host
Is connection refused proof that the localhost value is wrong?
No. A wrong destination is one possibility, but the same error can occur if Ollama is stopped or not listening on the requested interface and port. A timeout points more strongly toward a network path or filtering problem, but it is not proof by itself. Compare the same request from the host and from the Dify container.
Identify the Dify service name from the Compose file used for the deployment. Then open a shell in that service, replacing the placeholder:
docker compose exec <dify-service> sh
If the container has curl, request the same host address that will be used in the plugin:
curl http://<reachable-host-address>:11434/api/tags
The address must be identical to the candidate Base URL’s host and port. If the container image lacks curl, use an approved diagnostic method that runs in the same Docker network. A test from an unrelated container or from the host does not establish that the Dify service can reach Ollama.
Use this sequence to isolate the fault:
- Host request fails: check Ollama service status and local listener.
- Host request succeeds, container request fails: check address selection, Docker network routing, listener binding, and firewall rules.
- Both requests succeed, but Dify fails: check plugin fields and model configuration.
- Dify’s model test succeeds, but an Agent fails: inspect workflow, tool, and sandbox behavior separately.
A response from the tags endpoint confirms that Ollama answered the request. It does not prove that the model selected in Dify is suitable for every workflow.
Fourth check: Match the plugin settings to the loaded model
Check the plugin’s Base URL, port, model name, model type, and context setting against the current configuration shown by the plugin. The Base URL should identify the service root expected by the plugin. The model name should match the name Ollama reports, including any tag or variant that distinguishes the loaded model.
To list the names Ollama currently reports, use the documented endpoint:
curl http://<reachable-host-address>:11434/api/tags
Compare its response with the model selected in Dify. A mismatch can produce a “model not found” error even when the network connection is healthy.
Also check whether the selected model is configured for the function the workflow needs. Chat, embeddings, image input, and tool calling are not interchangeable capabilities. If a basic chat request succeeds but a RAG retrieval or Agent step fails, the problem may be the selected model type, its declared capabilities, or the workflow’s use of it—not the connection to Ollama.
To separate transport from model behavior, use a minimal request from the Dify container:
curl http://<reachable-host-address>:11434/api/chat \
-H 'Content-Type: application/json' \
-d '{"model":"<loaded-model-name>","messages":[{"role":"user","content":"Reply with one short sentence."},"],"stream":false}'
Replace the address and model name with values from the deployment. Check the current Ollama API documentation for request format and endpoint behavior. A successful response shows that the network path and Ollama request reached the model. It does not guarantee that Dify’s plugin fields or Agent tools are configured correctly.
Fifth check: Separate model connectivity from Agent access
If the Dify model test succeeds and a simple chat app works, stop changing the Ollama listener. Move to the failing workflow step.
An Agent can depend on tools or internal services that follow different access rules from the model request. Dify versions, container components, and security settings can change how internal addresses are handled. Review the current deployment documentation and relevant service logs before changing environment variables or proxy settings. Do not treat a workaround from another deployment as a universal fix.
Use the decision branches below to choose the next action:
- If the host request fails, repair the Ollama service or its local listener before touching Dify.
- If the host request works but the Dify-container request fails, check the container-to-host address, Docker network, listener binding, and firewall; do not alter the model name yet.
- If the container request works but Dify reports a missing model, compare the plugin’s model name and model type with Ollama’s loaded-model list.
- If Dify chat works but an Agent or workflow fails, inspect the failing tool, sandbox, workflow configuration, and logs; keep the working model connection unchanged.
- If only a public route makes the connection work, stop and redesign the access path. Do not expose an unauthenticated Ollama endpoint to the internet.
The safe target is the narrowest access that lets the Dify service reach the model. Keep the model API private to the required host or container network.
Decide whether to keep the PoC on one machine
A single-machine PoC can reduce the number of network paths when Dify, Ollama, and the supporting knowledge-base services are all intended to run together. It does not remove the need to test addresses from inside each container. Separate services may be appropriate when their resource needs, access policies, or operational ownership differ.
Choose based on the actual workload:
- If the immediate goal is to validate a Dify workflow against a local model, first get one minimal chat request working across the intended network path.
- If Dify, the model, and knowledge-base services must share a host, verify their resource and storage requirements against the model and data actually used.
- If several users or workflows will use the system, measure the real workload before selecting a deployment layout. This guide does not predict concurrency or inference speed.
- If the PoC needs an accelerator for local model inference, do not assume a general-purpose CPU server replaces DGX Spark or another suitable accelerator.
For an AI prototype team considering a temporary DGX Spark environment, check the current DGX Spark configuration page for the published machine options and terms. Do not assume daily billing, a particular price, or a setup-fee policy unless the live product information states it. If the page publishes a daily rate, calculate the rental total from the stated rental days and rate; otherwise, use the billing terms actually shown. The billing guide can help clarify the published billing method.
For the Dify stack itself, compare the current setup with an exclusive AMD physical server only when its CPU and memory resources fit the application, retrieval, or supporting services. A dedicated AMD server can provide an isolated host for those workloads, but it is not a GPU substitute for local model inference. Shared VPS or cloud instances can be a better fit for a short test or a workload that needs rapid scaling; weigh their resource isolation and billing model against the actual PoC requirements.
Once the connection path is stable, use the published DGX Spark options and billing terms to decide whether a dedicated environment is justified for the next test. If the model must stay local and the workload needs an accelerator, choose based on the verified DGX Spark configuration—not an assumed performance figure.
AMD EPYC 7543P Dedicated Server
From $455.2/month