Running Ollama in Docker with NVIDIA GPUs: when a container fits
A container is a sound choice when a team wants a shared Ollama server on NVIDIA hardware and already runs container platforms that its operators know how to patch, monitor and back up. It is a weaker choice when the only goal is one developer trying a model on a laptop, because the container adds a layer of GPU plumbing that has to work before any model loads. Ollama itself is an open source runtime under the MIT license, written in Go with a llama.cpp backend, so the license does not decide the question. The deployment shape does.
The container adds three things. It gives you isolation from the host's other services, a repeatable image that can be rebuilt and rolled back, and a place to keep model weights on a named volume rather than inside the image. Ollama serves its REST API on port 11434, and the server binds to 127.0.0.1 by default, so inside a container the published port and the bind address must be set deliberately or the API will be unreachable from the host or the network. Plan the volume mount for the model directory before the first pull, because models are large and losing them on a container rebuild costs time and bandwidth.
The container does not solve access control, and it does not make the GPU work by itself. The local API has no authentication, so anyone who can reach the published port can run inference, and the security section of this page covers the proxy and identity layer you need. The container also does not remove the need for a working host driver and the NVIDIA Container Toolkit. Confirm with your platform team who owns host driver updates, how image tags are pinned and which Ollama release you will standardize on, since releases move often. Check the current requirements in the Ollama GitHub repository before you commit to an image tag.
Which Docker run options fit which deployment
A single developer usually runs one container on a workstation with one or two NVIDIA GPUs and wants the fewest moving parts. The default Ollama settings are often enough, and the main decision is whether the API should be reachable from anywhere other than the local machine. Ollama binds to 127.0.0.1 on port 11434 by default, and the local API does not require authentication, so keeping that default is the safest choice for one user.
- GPU flag:
--gpus allis the simplest form and exposes every GPU on the host to the container. - Model storage: a named volume is enough, since the developer does not need to browse model files on the host.
- Bind address: leave
OLLAMA_HOSTunset so the API stays on localhost. - Concurrency: keep the defaults, which are 1 parallel request per model, 3 loaded models per GPU and a queue of 512 requests.
- Model directory:
OLLAMA_MODELSonly matters if the default path inside the container is too small for the model library.
Check that docker exec into the container lists the models you pulled and that the API answers on localhost before you add anything else.
A shared team server serves several people and applications from one host, so the run options must balance access, storage durability and capacity. Exposing the API beyond localhost means the network path must be protected, because Ollama's local API has no built-in authentication. Concurrency settings become important as soon as more than one person sends requests at the same time.
- GPU flag:
--gpuswith a device list, such asdevice=0,1, keeps other workloads on the host off the Ollama container. - Model storage: a bind mount to a dedicated disk makes model files easy to back up, size and clean up.
- Bind address: set
OLLAMA_HOSTto an internal interface and place an authenticated reverse proxy in front of it. - Concurrency: raise
OLLAMA_NUM_PARALLELonly after measuring GPU memory, and reviewOLLAMA_MAX_LOADED_MODELSandOLLAMA_MAX_QUEUEagainst expected load. - Ownership: make sure the directory on the host is writable by the user the container runs as.
Confirm the queue behavior and memory use under a realistic test load with the team's own models before you publish the endpoint.
In a restricted network the host may have no outbound internet access, so models must already be on local storage and cloud features must be disabled. The run options focus on keeping data inside the environment, pinning the image and making the model directory a controlled, reviewed location. Ollama states that cloud features can be turned off with OLLAMA_NO_CLOUD=1 or the server configuration file.
- GPU flag: select specific devices so that the container only receives the GPUs approved for the workload.
- Model storage: use a bind mount to a directory populated through an internal transfer process, and keep it read-controlled.
- Cloud features: set
OLLAMA_NO_CLOUD=1so the server does not use cloud inference. - Bind address: keep
OLLAMA_HOSTon an internal address and restrict access with network policy. - Image source: pull the image from an internal registry, and record the version you tested.
Confirm with your security team how the model files and the image get into the network, and whether the chosen settings meet your internal change control.
The three concurrency variables control different limits, and they are often confused. OLLAMA_NUM_PARALLEL sets how many requests one model handles at once, and its documented default is 1. OLLAMA_MAX_LOADED_MODELS sets how many models stay in memory, with a documented default of 3 times the number of GPUs, or 3 on CPU. OLLAMA_MAX_QUEUE sets how many requests wait, with a documented default of 512.
- Single developer: the defaults fit most cases, since one person sends one request at a time.
- Shared team server: raise parallelism only after checking GPU memory, because each parallel slot needs room for context.
- Loaded models: lower the loaded model count if several large models compete for VRAM.
- Queue length: a larger queue delays failure rather than preventing it, so set it with clients that handle timeouts.
- Restricted network: the same values apply, but capacity is fixed by the approved hardware, so plan limits in advance.
Run a load test with your own models and context sizes to confirm the values before you publish the service.
Setup sequence for an NVIDIA GPU container
This sequence takes a GPU host from a driver check to a containerized Ollama server that loads models onto the GPU and keeps them in a named volume across container restarts. Each step closes with a check, so a failure is caught at the layer where it occurs. A platform or infrastructure engineer with root access to the host carries out the steps.
Verify the host NVIDIA driver
Run
nvidia-smion the Docker host, outside any container. The platform engineer with root access does this first, because every later step depends on a working driver. A correct result is a table listing each GPU model, its memory and a driver version. If the command is missing or reports no devices, fix the driver installation before continuing, since the container toolkit cannot expose a GPU the host does not see. Record the driver version and confirm with your vendor documentation that it is supported by the toolkit release you plan to install.Install the NVIDIA Container Toolkit
Install the NVIDIA Container Toolkit packages from NVIDIA's repository for your Linux distribution, following NVIDIA's current installation guide. Then register the NVIDIA runtime with Docker by running
nvidia-ctk runtime configure --runtime=docker, and restart the Docker daemon. The platform engineer does this on each GPU host. The step is complete whendocker infolists an nvidia runtime alongside the default runtime. If the runtime is missing, confirm the daemon restarted and that the configuration file the command edited is the one Docker reads on your system.Confirm GPU access from a container
Run a short-lived container with
--gpus alland a CUDA base image from a registry your organization approves, executingnvidia-smi. Choose the image tag from NVIDIA's container documentation and confirm it supports your driver version. The check passes when the container prints the same GPU list you saw on the host. If it reports a driver or library error, the problem sits in the toolkit layer, so return to the toolkit step before changing anything in Ollama.Start the Ollama container with a volume
Start the server with
docker run -d --gpus all --name ollama -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 ollama/ollama. Confirm the model directory path in the image documentation for your version, since the volume target depends on it. The named volume keeps downloaded models outside the container, so recreating the container does not force a new download. Publishing the port on 127.0.0.1 keeps the unauthenticated API off the network. If the server inside the container binds only to loopback, port publishing cannot reach it, so check the bind setting in the logs. The step is complete whendocker psshows the container running anddocker logs ollamashows the server listening on port 11434.Pull a model into the volume
Run
docker exec -it ollama ollama pullfollowed by the name of a small model your organization has approved for testing. The model name is illustrative, so choose one that your model approval process allows. Pulling downloads the weights into the volume and needs outbound access to the model source, which may require a proxy in restricted networks. The step is complete whendocker exec ollama ollama listshows the model with its size and modification time.Check GPU use in logs and nvidia-smi
Send one prompt with
docker exec -it ollama ollama runand the model name, then check three things. Rundocker logs ollamaand look for lines reporting GPU detection and the compute library in use, not a CPU-only fallback. Rundocker exec ollama ollama psto see how the loaded model is split between GPU and CPU. Runnvidia-smion the host and confirm GPU memory use rises while the model is loaded. If the logs show no GPU, check the container's device access before tuning any concurrency settings.Confirm models survive container recreation
Remove the container with
docker rm -f ollama, then start it again with the samedocker runcommand and the same volume name. Rundocker exec ollama ollama listagain. The model should still be listed without a new download. This final check shows that the volume, not the container, holds the models. Record the volume name, image tag and driver version in your runbook so the next person can rebuild the host.
Fixing GPU loss caused by systemd cgroup management
The usual symptom is that the Ollama container starts with GPU access, runs correctly for a while, then reports no GPU or falls back to CPU after the host's systemd reloads units, a daemon restarts or the host reboots. Running nvidia-smi inside the container fails with a message that it cannot communicate with the driver, even though nvidia-smi on the host still works. The cause is that the NVIDIA Container Toolkit grants a container access to device files through cgroup rules, and systemd on the host also manages cgroups for the container's scope. When systemd rewrites those rules during a daemon reload, it can remove the device permissions the toolkit granted, and the running container loses its GPU devices without any change to the container itself.
The remedy depends on the host's cgroup driver and the container runtime's settings, so confirm the exact steps against the NVIDIA Container Toolkit documentation for your version rather than copying a configuration from a forum. The configuration usually involves choosing a cgroup driver consistently for the container runtime and telling the toolkit how to manage device access. Record which cgroup driver the host uses, which runtime settings you changed and which toolkit version you installed, because a later toolkit or driver upgrade can change the correct answer. Keep the Ollama container definition, including the --gpus flag or Compose device reservation, under version control so the same settings are reapplied after a rebuild.
Do not assume the fix holds because the container started once. Test after a systemctl daemon-reload, after restarting the Docker daemon and after a full host reboot, and run nvidia-smi inside the Ollama container each time. Then send a small generation request and confirm in the Ollama logs that the model loaded on the GPU and not on the CPU. Schedule this check as part of every host patch window, since kernel, driver and toolkit updates can reintroduce the problem. If the fix fails only after a reboot, check whether the container starts before the NVIDIA driver modules are ready, because that is a start-order problem that a restart test alone will not reveal.
Security considerations for a containerized Ollama server
A containerized Ollama server is only as safe as the network path to it. The local API on port 11434 has no authentication, so the bind address, published ports, storage permissions and proxy layer have to be designed together. The cards below cover the decisions and checks that connect those layers on an NVIDIA GPU host.
Authentication sits outside Ollama
The local API at port 11434 does not require authentication, so anyone who can reach it can run models and read what the server exposes. Put a reverse proxy with authentication in front of it, such as an identity-aware gateway or an Nginx layer, and make the proxy the only path to the API. Confirm that no route bypasses it, including direct access on the GPU host. Test this from a machine outside the trusted network.
API authentication docsBind address and published ports
Ollama binds to 127.0.0.1 on port 11434 by default. In Docker, setting OLLAMA_HOST to 0.0.0.0 inside the container and publishing the port with -p can expose the API to every interface on the host. Publish the port only on the address the proxy uses, for example 127.0.0.1:11434:11434, and check the result with a port scan from another machine. Document the chosen values so a later compose change does not reopen the API.
Model volume permissions
The model volume holds every downloaded model, and its ownership decides who can read, replace or delete weights. Mount a named volume or a dedicated host directory, and give it ownership that matches the user the Ollama process runs as. Keep write access limited to the service and the administrators who manage models. Confirm the path with OLLAMA_MODELS if you move the models directory, because a mismatch often leads teams to loosen permissions instead.
Avoid unnecessary container privileges
GPU access needs the device passed through, but that does not require a privileged container. Avoid --privileged, avoid host PID and network namespaces, and drop capabilities the server does not need. Run with a read-only root filesystem where the image allows it, and keep the model volume as the only writable data path. Ask your platform team to review the final docker run or compose file against this list before go-live.
Keep the image and driver patched
Ollama ships frequent releases, and the container image pins a version that must be tracked and updated like any other service. Record the image tag and digest in your deployment record, subscribe to the release feed, and test each update on a staging host with the same GPU. Patch the NVIDIA driver and Container Toolkit on the host as part of the same cycle, since both sit in the GPU path.
Ollama release notesTurn off cloud features for local data
Ollama states that when it runs locally it does not see your prompts or data, but cloud features are a separate path that you control. When data must stay inside your environment, set OLLAMA_NO_CLOUD=1 in the container environment or in the server configuration file. Verify the setting by confirming that cloud model requests fail, and record the check in your change log. Cloud inference uses an API key sent as a Bearer token, so also confirm that no keys are stored in the container.
How the host, toolkit and Ollama container fit together
The diagram starts at the NVIDIA driver on the Linux host, which the Container Toolkit depends on to pass GPU devices into Docker. Docker's runtime then starts the Ollama container with the GPU granted through the --gpus flag, and the model volume holds weights outside the container's writable layer. Client applications reach port 11434 only through a trust boundary or reverse proxy, so the check is that the GPU is visible inside the container and that the API is not exposed directly.
Driver, toolkit, Docker runtime and Ollama container with the model volume and client path.
Questions buyers ask before running Ollama on NVIDIA GPUs in Docker
Does Ollama itself cost money to run in Docker?
Running Ollama on your own hardware is free under the MIT license, and Ollama's pricing page states that running models on your own hardware is always unlimited. The paid plans on that page cover cloud models, so a self-hosted container on your GPUs does not add a license fee. Your costs are the hardware, the GPU drivers, storage for model files, the staff time to run the container, and any outside help you choose to buy. Confirm with your procurement team whether any cloud model features you plan to use fall under a paid plan.
What drives the effort of a Docker setup with NVIDIA GPUs?
Most of the effort sits in the host, not in the container. The main drivers are the NVIDIA driver version on each host, the NVIDIA Container Toolkit, the number and type of GPUs, how many services share those GPUs, and whether the host is managed by systemd cgroup settings that can drop GPU access. Next come the persistent model volume, the environment variables for concurrency and bind address, and how the API is exposed to users. Each host you add multiplies the checks.
How long does a Docker GPU setup take?
The duration depends on how many hosts you have, how standard they are, and whether drivers are already installed and approved. A single host with a supported driver and no change control is a much smaller job than a fleet with mixed GPUs, locked kernels and a change window. Ask any provider for a written schedule tied to the host count, driver state, and the test steps they will run before handover. Your own team can estimate the same way by listing hosts, approvals and test runs.
What must our team provide before the work starts?
You need to provide the target hosts with supported NVIDIA GPUs, administrator access through your change process, the driver version your standards allow, network rules for pulling images and models or an internal mirror, and the storage location for model files. You also need to choose the models to load, the users or applications that will call the API, and who owns the server after handover. If the server will be reached from other machines, decide the access method before the build, because Ollama's local API does not require authentication.
Can our own engineers set this up without outside help?
Yes, if you have a team comfortable with Linux, Docker, NVIDIA drivers and systemd. The work is documented in the upstream Ollama image and the NVIDIA toolchain, so a capable engineer can follow it. The points where internal teams usually need a second check are GPU loss after a reboot or systemd change, volume permissions for the model directory, and driver upgrades that break the container runtime. Plan a test run that restarts the host, reloads a model and confirms GPU use before you call the build finished.
What goes wrong most often with GPUs in containers?
The most common failure is the container losing access to the GPU after the host restarts or after systemd reloads cgroup settings, so the model falls back to CPU without an obvious error. Other frequent problems are a missing or mismatched NVIDIA Container Toolkit, a driver that does not match the runtime, model files written to a path the container cannot write, and a bind address left at its default so clients cannot reach the server. Check GPU visibility from inside the container after every host change.
Does running Ollama in Docker keep our prompts private?
Ollama states that when it runs locally it does not see your prompts or data, and cloud features can be turned off with OLLAMA_NO_CLOUD=1 or the server configuration file. Privacy in practice also depends on your network settings, logs, and who can reach the API port. Because the local API has no authentication, anyone who can reach the port can use your models. Put access control and network limits in front of it, and confirm the cloud setting is applied in the running container.
Will a Docker deployment meet our compliance requirements on its own?
A container setup is one input to a compliance review, not a certification. Your auditors will look at access control, logging, change records, backup of model storage and the configuration you can show them. DeployOpen can prepare systems, controls and evidence for a compliance assessment, but independent auditors and certification bodies issue any report or attestation. Ask your auditor which evidence they need before the build so the configuration and logs are captured from the start.
How DeployOpen scopes and delivers this work
DeployOpen plans, builds, tests, documents and supports Ollama inside your own infrastructure, including the NVIDIA GPU hosts, container runtime and model volumes described on this page. Each engagement starts from a written scope that names the hosts, GPUs, driver baseline and Ollama version your team needs to run.
How we scope
- Inventory the GPU hosts, driver versions, container runtime and operating system your team will run Ollama on.
- Agree which Ollama image tag, NVIDIA Container Toolkit setup and --gpus configuration the containers will use.
- Define the persistent volume layout for model storage, sized against the models your team has approved.
How we build
- Install and configure the NVIDIA Container Toolkit and verify GPU access from inside a container.
- Set OLLAMA_HOST, OLLAMA_MODELS and concurrency variables in the compose or run definition, then document each value.
- Test GPU loss after host reboots and systemd cgroup changes, and apply the fix that matches your host configuration.
How we hand over
- Deliver the container definitions, environment file, volume mapping and host configuration as files in your repository.
- Provide a start-up check list covering GPU visibility, model pull, model load and API response on port 11434.
- Document the upgrade and rollback steps for the Ollama image and the NVIDIA driver and toolkit versions.
How we support
- Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
- Ongoing support, upgrades and continuous testing are available as a retainer, and a quote follows from the written scope.
- Ask us to confirm which parts of the stack your own team keeps, such as driver patching, host monitoring and model approvals.

