cheat-sheets

Ollama

Run open-weight language models locally with one command and a local HTTP API. Use it as the model backend for Open WebUI, Aider and scripts.

Project: Ollama Documentation: Ollama docs · Model library

Verification: commands, environment variables and API paths are from the official docs and CLI help from memory; Ollama was not installed here, so nothing was executed. Model tags change; check the library. Items marked (unverified) need confirming.

Basics #

COMMANDDESCRIPTION
ollama serveStart the server (the Linux installer sets this up as a systemd service)
ollama run MODELChat with a model, pulling it first if needed
ollama run MODEL "PROMPT"One-shot prompt
ollama pull MODELDownload a model
ollama listShow downloaded models
ollama psShow loaded models and memory use
ollama stop MODELUnload a model from memory
ollama show MODELShow details (parameters, template, licence)
ollama cp SOURCE TARGETCopy a model under a new name
ollama rm MODELDelete a model and free disk
ollama create NAME -f ModelfileBuild a model from a Modelfile
ollama push NAMEPublish to ollama.com (needs an account)

Model tags look like llama3.2:3b (name, then size or variant). Pick a size that fits your VRAM; see quantisation.

Modelfile #

text
FROM llama3.2:3b
PARAMETER temperature 0.3
PARAMETER num_ctx 8192
SYSTEM You are a terse homelab assistant.
INSTRUCTIONMEANING
FROMBase model or a GGUF path
PARAMETERRuntime option such as temperature, num_ctx, top_p
SYSTEMSystem prompt
TEMPLATEPrompt template (rarely needed)
ADAPTERApply a LoRA adapter

Environment Variables #

Set them in the service environment (sudo systemctl edit ollama), not just your shell.

VARIABLEUSE
OLLAMA_HOSTBind address and port (default 127.0.0.1:11434). 0.0.0.0 exposes it to the network, so firewall it
OLLAMA_MODELSModel storage directory
OLLAMA_KEEP_ALIVEHow long a model stays loaded (for example 10m, -1 forever)
OLLAMA_NUM_PARALLELConcurrent requests per model
OLLAMA_MAX_LOADED_MODELSModels kept loaded at once
OLLAMA_ORIGINSAllowed CORS origins (unverified)

HTTP API #

The API has no authentication. Do not publish port 11434; put an authenticating reverse proxy in front if you must.

bash
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2:3b",
  "prompt": "Why is the sky blue?",
  "stream": false
}'

curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2:3b",
  "messages": [{"role": "user", "content": "Hello"}],
  "stream": false
}'

curl http://localhost:11434/api/tags
ENDPOINTUSE
POST /api/generateSingle prompt completion
POST /api/chatChat with message history
GET /api/tagsList local models
POST /api/embedEmbeddings (unverified: older versions used /api/embeddings)
/v1/chat/completionsOpenAI-compatible endpoint; see OpenAI API

Docker #

GPU use needs the NVIDIA Container Toolkit on the host. For a VM, pass the GPU through first: Proxmox GPU and PCIe Passthrough. See Docker Compose for the file format.

yaml
services:
  ollama:
    image: ollama/ollama:<TAG>
    restart: unless-stopped
    ports:
      - "127.0.0.1:11434:11434"
    volumes:
      - ollama:/root/.ollama
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
volumes:
  ollama:
COMMANDDESCRIPTION
docker exec -it ollama ollama pull MODELPull inside the container
docker exec -it ollama ollama psCheck whether the model is on GPU (PROCESSOR column)

Troubleshooting #

SYMPTOMFIX
Runs on CPU onlyCheck nvidia-smi works on the host and the container has the GPU; read journalctl -u ollama
Model slow or out of memoryUse a smaller size or heavier quantisation; lower num_ctx
Remote client cannot connectServer binds to loopback by default; set OLLAMA_HOST and open the firewall deliberately
Disk fills upollama list then ollama rm MODEL

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.