Skip to content

Ollama

Install

1
npm install @testcontainers/ollama --save-dev

Examples

Choose an image from the container registry and substitute IMAGE.

Pull and commit an image

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
await using container = await new OllamaContainer(IMAGE).start();
await container.exec(["ollama", "pull", "all-minilm"]);

const response = await fetch(`${container.getEndpoint()}/api/tags`);
expect(response.status).toEqual(200);
const body = (await response.json()) as { models: { name: string }[] };
expect(body.models[0].name).toContain("all-minilm");

const newImageName = "tc-ollama-allminilm-" + randomUuid().substring(4);
await container.commitToImage(newImageName);

await using newContainer = await new OllamaContainer(newImageName).start();
const newResponse = await fetch(`${newContainer.getEndpoint()}/api/tags`);
expect(newResponse.status).toEqual(200);
const newBody = (await newResponse.json()) as { models: { name: string }[] };
expect(newBody.models[0].name).toContain("all-minilm");