Home

Ollama

qianmoQqianmoQ· 更新于 2026-10-13· 阅读 3 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

Ollama

Testcontainers module for Ollama .

Ollama's usage examples

You can start an Ollama container instance from any Java application by using:

Ollama container

OllamaContainer ollama = new OllamaContainer("ollama/ollama:0.1.26")

Pulling the model

Testcontainers allows executing commands in the container. So, pulling the model is as simple as:

Pull model

ollama.execInContainer("ollama", "pull", "all-minilm");

Create a new Image

In order to create a new image that contains the model, you can use the following code:

Commit Image

ollama.commitToImage(newImageName);

And use the new image along with Image name Substitution

Use new Image

OllamaContainer ollama = new OllamaContainer(
    DockerImageName.parse(newImageName)
        .asCompatibleSubstituteFor("ollama/ollama")
)

Adding this module to your project dependencies

Add the following dependency to your pom.xml/build.gradle file:

GradleMaven

testImplementation "org.testcontainers:testcontainers-ollama:2.0.5"
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers-ollama</artifactId>
    <version>2.0.5</version>
    <scope>test</scope>
</dependency>

评论

登录后参与评论

正在加载评论…