Skip to main content
This blog post is authored by Eddú Meléndez.
Docker recently released a Model Runner in Docker Desktop for Mac 4.40.0 on Apple silicon. The Docker Model Runner provides a local Inference API designed to be compatible with the OpenAI API, enabling easy integration with Spring AI as part of the Spring AI 1.0.0-M7 release. Models are distributed as standard OCI artifacts on Docker Hub under the ai namespace.

Prerequisites

  • Download Docker Desktop for Mac 4.40.0.
  • Choose one of the following options to enable the Model Runner: Option 1:
  • Enable Model Runner `docker desktop enable model-runner —tcp 12434`.
  • Set the base-url to `http://localhost:12434/engines\` Option 2:
  • Enable Model Runner `docker desktop enable model-runner`.
  • Use Testcontainers and set the base-url as follows:
Next, pull the model `docker model pull ai/gemma3` and confirm it is available locally `docker model list`

Dependencies

Go to start.spring.io, select Spring Web, OpenAI and Testcontainers and generate the project. The following dependencies must be listed
Also, make sure the Spring AI BOM is present
Configuring Spring AI To use Docker Model Runner, we need to configure the OpenAI client to point to the right endpoint and use the model pulled earlier For Option 1: Let’s configure the src/main/resources/application.properties
For Option 2 (Using Testcontainers): Let’s go to `TestcontainersConfiguration`, define the SocatContainer bean and register the properties with `DynamicPropertyRegistrar` bean.

Chat example

Now, let’s create a simple controller
Run the application with `./mvnw spring-boot:test-run` Using httpie, let’s call to the `/chat` endpoint
We can also call to the `/chat-stream` endpoint

Tool example

Docker Model Runner of course supports tool calling if used with a model that supports tool calling. Create a `FunctionCallConfig` class and add a simple function
Now, let’s register `stockFunction` function
Run the application `./mvnw spring-boot:test-run` and call the `/stocks` endpoint
The response should be something like `AAPL stock price is 198.0 and NVDA stock price is 114.0.` based on the hardcoded values we set.

References

Conclusion

Docker Model Runner allows you to iterate faster, stay local and access an OpenAI-compatible API. It streamlines the development experience by enabling seamless integration with Spring AI’s OpenAI module, letting developers stay within their familiar inner-loop tooling. This empowers teams to build and test AI applications at their own pace—locally, securely, and efficiently. In the future, integration with Testcontainers will make it even easier to pull and run models on demand, further simplifying setup and testing workflows.Docker Model Runner allows you to iterate faster, stay local and access an OpenAI-compatible API. It streamlines the development experience by enabling seamless integration with Spring AI’s OpenAI module, letting developers stay within their familiar inner-loop tooling. This empowers teams to build and test AI applications at their own pace—locally, securely, and efficiently.