Hosted AI services are convenient, but they are not always the right choice for every workload. A local model can help developers experiment with prompts, build prototypes, automate private workflows and avoid sending every request to an external API. It also gives teams more control over model selection and runtime configuration.
Introduction: why run an AI model locally?
Local inference is not automatically free or private in every respect. Hardware limits model size and response speed, and applications may still send data to external services if they are configured to do so. This guide uses Ollama in Docker as a practical starting point.
Prerequisites and hardware planning
Install Docker Desktop on Windows or Docker Engine on Linux, and make sure virtualization is enabled where required. For GPU acceleration, install a compatible NVIDIA driver and configure the container runtime so Docker can access the GPU. Verify GPU visibility before troubleshooting Ollama itself.
RAM and VRAM determine which models are practical. A model's parameter count is only one part of memory usage: quantization, context length, runtime overhead and concurrent requests also matter. Start with a small model and increase size only after measuring actual memory consumption and response time.
Start Ollama with Docker
Create a persistent Docker volume so downloaded models survive container recreation. A basic deployment can expose Ollama's API on the host and mount the volume at the application's model directory. Keep the port bound to localhost for a development machine rather than exposing it to the public internet.
Example command: docker run -d –name ollama -p 127.0.0.1:11434:11434 -v ollama:/root/.ollama ollama/ollama. This starts the CPU-capable container with persistent model storage. GPU configuration is platform-specific; consult the official Ollama and Docker documentation for the correct NVIDIA runtime options for your operating system.
Download and run a model
Once the container is running, download a model with docker exec -it ollama ollama pull qwen2.5:7b, provided that model tag is available in the Ollama library. Then start an interactive session with docker exec -it ollama ollama run qwen2.5:7b. Model names and tags change, so check the library before selecting a version.
Try a simple task first, such as summarizing a short paragraph or generating a small code example. Increase the context window gradually. A very large context can consume substantially more memory and may reduce the number of concurrent requests your machine can handle.
Call the local HTTP API
Ollama exposes an HTTP API that applications can use. From the host, the API is commonly available at http://localhost:11434. A request to the generate endpoint includes the model name, prompt and optional generation settings. For example, send a JSON body containing model, prompt and stream=false to /api/generate.
From another container, localhost refers to that container itself, not the Ollama container. Put both services on the same Docker network and use the Ollama service name as the hostname. This networking detail is a frequent cause of connection errors in n8n and other containerized applications.
Connect a workflow such as n8n
In n8n, configure an HTTP Request node to call the Ollama API. Use the Docker service name and port when n8n and Ollama share a network. Send the prompt as JSON and parse the response field returned by the API. For production workflows, add timeouts, retries with limits and clear handling for model errors.
Keep prompts and generated outputs separate from credentials. If a workflow publishes content, insert a review step before publication. A local model can draft an article, but it should not be trusted to invent facts, citations or image licenses.
GPU troubleshooting and performance
If the model runs slowly, first determine whether the container can see the GPU. Check the host driver, Docker GPU support and container logs. Compare GPU utilization and memory usage while generating a response. If the model exceeds available VRAM, it may offload some work to system RAM, which can make generation much slower.
Reduce model size or quantization, shorten the context and avoid running several large models at once. Do not assume that a container restart fixes a driver or runtime configuration problem. Change one variable at a time and record the result.
Security and maintenance
Do not expose the Ollama API publicly without an authenticated gateway and network controls. The local API is designed for trusted environments and should not be treated as a complete public-facing security boundary. Keep Docker images and model versions under control, and monitor disk usage because model files can consume many gigabytes.
Back up important workflow configuration and prompts. Document the model tag used by each application so that an update does not silently change output quality. Evaluate model behavior on representative tasks before upgrading.
Conclusion
Ollama and Docker provide a straightforward way to experiment with local language models and connect them to developer tools. Begin with a modest model, persistent storage and a localhost-only API. Validate GPU access, container networking and output quality before turning a prototype into an automated production workflow.
Frequently asked questions
Can Ollama use an NVIDIA GPU in Docker?
Yes, when the host driver and Docker GPU runtime are configured correctly for the platform.
Is the Ollama API safe to expose publicly?
Do not expose it directly. Keep it on a trusted network or protect it behind an authenticated gateway.