Image, container and Compose
Image, container and Compose — Docker Compose for AI services. Define the reproducible unit; Record the image identity; Write the first Compose file. Practical assignment: Practice: Image, container and Compose.
Demo edition. The materials are undergoing editorial review.
Topics covered
- Define the reproducible unit
- Record the image identity
- Write the first Compose file
Define the reproducible unit
An image supplies filesystem content and defaults; a container is a running instance with its own state. Compose describes which instances exist and how they connect. Our educational system is one CPU-only Ollama server, initially without downloaded models. This separates infrastructure checks from the disk and memory requirements of model weights. Use an existing lab installation of Docker Engine and the Compose plugin. Docker daemon access carries broad authority; never hand its socket to a model or untrusted container.
docker version
docker compose version
Record the image identity
A moving latest tag may point to a different image tomorrow. Choose a published supported tag from official ollama/ollama, review its release notes and record its digest after retrieval. Examples require OLLAMA_IMAGE: Compose fails until you supply a verified reference rather than silently using an invented version. Store that reference in a local .env without secrets. Matching image versions do not guarantee matching weights; record the model identity and its license separately before any download.
Write the first Compose file
Save compose.yaml in the lab directory. The server listens on container port 11434, while the host mapping explicitly uses loopback. A named volume preserves Ollama's directory beyond container replacement. Before up, run config --quiet: normal config can display substituted values, so avoid printing secrets through it. Successful validation establishes configuration syntax, not model readiness. If OLLAMA_IMAGE is unset, expect an explanatory failure rather than automatic startup using an arbitrary image version.
name: ai-lab
services:
model:
image: ${OLLAMA_IMAGE:?Set a verified Ollama image reference}
ports:
- "127.0.0.1:11434:11434"
volumes:
- model_data:/root/.ollama
volumes:
model_data:
docker compose config --quiet
Practical assignment
Practice: Image, container and Compose
Continue to learning