Ollama Memory Configuration
When running Ollama on xCloud, you may encounter memory errors like:
500: model requires more system memory (4.5 GiB) than is available (2.0 GiB)This happens because the Ollama Docker container has a memory limit (often 2GB by default), even if your server has more RAM available.
Prerequisites
Section titled “Prerequisites”- SSH access to your xCloud server (see SSH Setup)
- Access to the Server Command Runner in xCloud dashboard
Diagnosing the Issue
Section titled “Diagnosing the Issue”Check Container Memory Limit
Section titled “Check Container Memory Limit”Run via SSH or the xCloud Command Runner:
docker inspect $(docker ps -q --filter name=ollama) | grep -i memoryLook for the "Memory" value. 2147483648 = 2GB, which is often too low for larger models.
Check Your Model Requirements
Section titled “Check Your Model Requirements”Different models require different amounts of RAM:
- llama2-uncensored (7B): ~4.5GB
- deepseek-r1:1.5b: ~2GB
- llama2:13b: ~8GB
- llama2:70b: ~40GB+
Fixing the Memory Limit
Section titled “Fixing the Memory Limit”Step 1: Get Current Container Configuration
Section titled “Step 1: Get Current Container Configuration”Save the volume mount path before removing the container:
docker inspect ollama-your-domain.com --format '{{range .Mounts}}{{.Source}}:{{.Destination}}{{"\n"}}{{end}}'Example output: /var/www/your-domain.com/data:/root/.ollama
Step 2: Stop and Remove the Old Container
Section titled “Step 2: Stop and Remove the Old Container”docker stop ollama-your-domain.com && docker rm ollama-your-domain.comStep 3: Recreate with More Memory
Section titled “Step 3: Recreate with More Memory”Replace <VOLUME_PATH> with your path from Step 1:
docker run -d --name ollama-your-domain.com --memory=12g --restart unless-stopped -p 127.0.0.1:18016:11434 -v <VOLUME_PATH>:/root/.ollama ollama/ollama:latestFor example:
docker run -d --name ollama-your-domain.com --memory=12g --restart unless-stopped -p 127.0.0.1:18016:11434 -v /var/www/your-domain.com/data:/root/.ollama ollama/ollama:latestStep 4: Verify the New Limit
Section titled “Step 4: Verify the New Limit”docker inspect ollama-your-domain.com --format '{{.HostConfig.Memory}}'Should return 12884901888 (12GB).
Reconnecting Open WebUI
Section titled “Reconnecting Open WebUI”After recreating the Ollama container, Open WebUI may lose connection because the container is no longer on the same Docker network.
Step 1: Find the Open WebUI Network
Section titled “Step 1: Find the Open WebUI Network”docker inspect $(docker ps -q --filter name=openweb) --format '{{range $k, $v := .NetworkSettings.Networks}}{{$k}}{{end}}'Step 2: Connect Ollama to the Network
Section titled “Step 2: Connect Ollama to the Network”docker network connect --alias ollama <NETWORK_NAME> ollama-your-domain.comFor example:
docker network connect --alias ollama your-openwebui-network-name ollama-your-domain.comThe --alias ollama is important because Open WebUI is configured to connect to http://ollama:11434.
Step 3: Verify Connection
Section titled “Step 3: Verify Connection”In Open WebUI:
- Go to Admin Settings > Connections
- Click the refresh button next to the Ollama API URL
- You should see “server connection verified”
Memory Limits Explained
Section titled “Memory Limits Explained”The --memory=12g flag sets a ceiling, not a reservation:
- Ollama can use up to 12GB, but only consumes what it actually needs
- Other apps can freely use any RAM that Ollama isn’t actively using
- No memory is pre-allocated or blocked from other containers
Your server’s total RAM should be higher than the sum of all container limits to avoid the OOM (Out of Memory) killer terminating containers.
Troubleshooting
Section titled “Troubleshooting””Failed to fetch models” in Open WebUI
Section titled “”Failed to fetch models” in Open WebUI”The Ollama container isn’t reachable. Check:
- Container is running:
docker ps | grep ollama - Container is on the correct network (see Reconnecting section above)
Model still shows memory error
Section titled “Model still shows memory error”Verify the container was recreated with the new limit:
docker inspect ollama-your-domain.com | grep '"Memory"'If it still shows 2GB, the container wasn’t properly recreated.
Container won’t start
Section titled “Container won’t start”Check Docker logs:
docker logs ollama-your-domain.com