With Ollama, what is a Modelfile for, and how do you build and run a named model from one?
answer
- configuration shipped once, not per call
- Dockerfile-shaped instruction file
- FROM is the only required line
- PARAMETER, SYSTEM, MESSAGE, TEMPLATE
- ollama create NAME -f Modelfile
basics
~20 sA Modelfile bakes a base model plus fixed settings (PARAMETER values, a SYSTEM prompt, seeded MESSAGE turns, a TEMPLATE) into one named model. ollama create support-bot -f Modelfile builds it; any call by that name then uses it.
solid answer
~50 sA Modelfile is Ollama's recipe for a customised model: a `FROM` line naming the base (a library model such as `llama3.2`, a GGUF file or a safetensors directory) plus optional instructions — `PARAMETER` for run options like `num_ctx`, `temperature` or `stop`, `SYSTEM` for the system prompt, `MESSAGE` for example turns, `TEMPLATE` for the prompt format, `LICENSE` and `REQUIRES`. `ollama create support-bot -f Modelfile` writes a new named model whose small config layers sit on top of the base's weights (reused, not copied, when the base is a model you already have), and from then on `ollama run support-bot`, `/api/chat` or `/v1/chat/completions` with `"model": "support-bot"` get those settings without the client sending them. The point is shipping configuration once: every app and teammate gets the same prompt and options, and `ollama show --modelfile support-bot` prints what is baked in.
code
dockerfile · 7 lines# Modelfile for a support assistant
FROM llama3.2
PARAMETER temperature 0.3
PARAMETER num_ctx 8192
SYSTEM """You are the support assistant for an internal ticketing tool. Answer briefly and ask for the ticket number when it is missing."""
MESSAGE user How do I reopen a ticket?
MESSAGE assistant Open the ticket and choose Reopen; you need the ticket number.go deeper
Recall that FROM is the only required instruction, that PARAMETER, SYSTEM and MESSAGE add fixed settings, and that ollama create NAME -f Modelfile builds a new model you then run by name.
Explain that create writes a new manifest reusing the base's weight blob plus small config layers, and use ollama show --modelfile to read what a library model already sets before building on it.
Argue for one named, version-controlled Modelfile per use case over options pasted into clients, and know a request's own system message or options can still override the baked values.
Weigh baking configuration into named models against keeping it in the application: one reviewable artifact and fewer drifting clients, versus a rebuild per prompt change and settings split across two places.
## The problem a Modelfile solves A team builds a **support assistant** on a local model. Without a Modelfile, every client has to send the same long system prompt, the same `temperature`, the same stop strings and the same context size on every request. Each new script, notebook or teammate copies that block by hand, and sooner or later one copy drifts. Ollama's answer is the **Modelfile**: a small text file that bakes a base model and its configuration into a **named model** that any client calls by name. The file has the same shape as a Dockerfile — one `INSTRUCTION arguments` per line, `#` for comments. The instruction names are not case sensitive and may appear in any order, though `FROM` is conventionally first. ## The instructions at a glance | Instruction | What it sets | Notes | |---|---|---| | `FROM` | the base model | **required**; a library model, a local GGUF file, or a safetensors directory | | `PARAMETER` | a run option | e.g. `num_ctx`, `temperature`, `stop`, `num_predict`; repeat `stop` for several stop strings | | `SYSTEM` | the system message | used when the request brings no system message of its own | | `MESSAGE` | seeded conversation turns | roles `system`, `user`, `assistant`; one line per turn | | `TEMPLATE` | the prompt format | Go template syntax with variables such as `.System`, `.Prompt`, `.Response`, `.Messages` | | `LICENSE` | licence text | carried with the model | | `REQUIRES` | minimum Ollama version | a semver such as `0.14.0` | What each sampling option *does* to generation is a decoding subject of its own; here the point is only that `PARAMETER` is where you pin it. ## Building and using the model The workflow is three commands: 1. Write the file, conventionally named `Modelfile`. 2. Run `ollama create support-bot -f Modelfile`. Without `-f`, the CLI looks for a file called `Modelfile` in the current directory. 3. Use it: `ollama run support-bot` in a terminal, or send `"model": "support-bot"` to `/api/chat`, `/api/generate` or the OpenAI-style `/v1/chat/completions`. Building does **not** copy the weights. When `FROM` names a model you already have, `ollama create` writes a new manifest that points at the base's existing weight blob and adds small layers for the system prompt, parameters, messages and template. The create output says so — lines such as `using already created layer sha256:...` for the reused blobs and `creating system layer` for the new one. A dozen variants of one 5 GB model cost a dozen tiny config layers, not 60 GB. ## Reading what a model already sets Before customising a library model, look at what it ships with: - `ollama show --modelfile llama3.2` prints a Modelfile reconstructed from the model — its `TEMPLATE`, its `PARAMETER stop` lines, any `SYSTEM` — with a comment telling you which `FROM` line to use if you build on it. - `ollama show --parameters`, `--template`, `--system` and `--license` print one part each. This matters because a library model's template and stop strings are what make it chat correctly; you usually inherit them by building `FROM llama3.2` rather than rewriting them. ## What a Modelfile does not do - It does not change the weights: `MESSAGE` turns are example context sent with each conversation, not training data. - It does not freeze a client's hands: a request that sends its own options or its own system message can still override what the model was built with for that request. - It is not how models are shared between machines on its own — the built model is pushed or pulled through a registry, a separate subject. ## Why interviewers ask The question separates someone who has wired a local model into an app from someone who has only chatted with one. A good answer names `FROM` as the one required line, knows `ollama create -f` builds a *new* model rather than editing the base, mentions `ollama show --modelfile` as the way to see what a model already carries, and explains the motive — one named, reviewable configuration instead of settings pasted into every call. The Modelfile can live in version control beside the application, so a change to the support assistant's prompt is a reviewed diff followed by `ollama create`, not a hunt through every client.
- Does `ollama create support-bot` duplicate the base model's weights on disk?No. When `FROM` names a model already present, the new manifest points at the same weight blob by its `sha256` digest, and `ollama create` writes only small new layers for the system prompt, parameters, messages or template. The create output lists the reused blobs as `using already created layer`, so many variants of one base cost little extra disk.
- You edit the Modelfile's SYSTEM line — how does the running model pick up the change?Nothing re-reads the Modelfile on its own; it is an input to `ollama create`, not a live config file. Run `ollama create support-bot -f Modelfile` again: it writes a new manifest under the same name with the new system layer, reusing the weight blob. Clients calling `support-bot` get the new prompt on their next request.
- Ollama reads the Modelfile at every request, so edits apply live
- Building FROM a local library model copies its full weights again
- A Modelfile edits the base library model in place
- Every Modelfile must restate TEMPLATE and SYSTEM explicitly
- A Modelfile fine-tunes the model on its MESSAGE examples