|
| 1 | +# Docker Model Runner |
| 2 | + |
| 3 | +Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> |
| 4 | + |
| 5 | +## Introduction |
| 6 | + |
| 7 | +The Testcontainers module for DockerModelRunner. |
| 8 | + |
| 9 | +## Adding this module to your project dependencies |
| 10 | + |
| 11 | +Please run the following command to add the DockerModelRunner module to your Go dependencies: |
| 12 | + |
| 13 | +``` |
| 14 | +go get github.com/testcontainers/testcontainers-go/modules/dockermodelrunner |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage example |
| 18 | + |
| 19 | +<!--codeinclude--> |
| 20 | +[Creating a DockerModelRunner container](../../modules/dockermodelrunner/examples_test.go) inside_block:runWithModel |
| 21 | +<!--/codeinclude--> |
| 22 | + |
| 23 | +## Module Reference |
| 24 | + |
| 25 | +### Run function |
| 26 | + |
| 27 | +- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> |
| 28 | + |
| 29 | +The Docker Model Runner module exposes two entrypoint functions to create the Docker Model Runner container: |
| 30 | + |
| 31 | +#### Run |
| 32 | + |
| 33 | +This function receives two parameters: |
| 34 | + |
| 35 | +```golang |
| 36 | +func Run(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) |
| 37 | +``` |
| 38 | + |
| 39 | +- `context.Context`, the Go context. |
| 40 | +- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. |
| 41 | + |
| 42 | +!!! info |
| 43 | + This function will use the default `socat` image under the hood. Please refer to the [socat module](../socat.md) for more information. |
| 44 | + |
| 45 | +### Container Options |
| 46 | + |
| 47 | +When starting the Docker Model Runner container, you can pass options in a variadic way to configure it. |
| 48 | + |
| 49 | +#### Image |
| 50 | + |
| 51 | +Use the second argument in the `Run` function to set a valid Docker image. |
| 52 | +In example: `Run(context.Background(), "alpine/socat:1.8.0.1")`. |
| 53 | + |
| 54 | +{% include "../features/common_functional_options.md" %} |
| 55 | + |
| 56 | +#### WithModel |
| 57 | + |
| 58 | +- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> |
| 59 | + |
| 60 | +Use the `WithModel` option to set the model to pull when the container is started. Please be aware, that only Models as OCI Artifacts are compatible with Docker Model Runner. |
| 61 | + |
| 62 | +```golang |
| 63 | +dockermodelrunner.WithModel("ai/llama3.2:latest") |
| 64 | +``` |
| 65 | + |
| 66 | +!!! warning |
| 67 | + Multiple calls to this function overrides the previous value. |
| 68 | + |
| 69 | + You can find a curated collection of cutting-edge AI models as OCI Artifacts, from lightweight on-device models to high-performance LLMs on [Docker Hub](https://hub.docker.com/u/ai). |
| 70 | + |
| 71 | +### Container Methods |
| 72 | + |
| 73 | +The Docker Model Runner container exposes the following methods: |
| 74 | + |
| 75 | +#### PullModel |
| 76 | + |
| 77 | +- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> |
| 78 | + |
| 79 | +Use the `PullModel` method to pull a model from the Docker Model Runner. |
| 80 | + |
| 81 | +<!--codeinclude--> |
| 82 | +[Pulling a model at runtime](../../modules/dockermodelrunner/examples_test.go) inside_block:runPullModel |
| 83 | +<!--/codeinclude--> |
| 84 | + |
| 85 | +!!! info |
| 86 | + You can find a curated collection of cutting-edge AI models as OCI Artifacts, from lightweight on-device models to high-performance LLMs on [Docker Hub](https://hub.docker.com/u/ai). |
| 87 | + |
| 88 | +#### InspectModel |
| 89 | + |
| 90 | +- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> |
| 91 | + |
| 92 | +Use the `InspectModel` method to inspect a model from the Docker Model Runner, by providing the model namespace and name. |
| 93 | + |
| 94 | +<!--codeinclude--> |
| 95 | +[Getting a model at runtime](../../modules/dockermodelrunner/examples_test.go) inside_block:runInspectModel |
| 96 | +<!--/codeinclude--> |
| 97 | + |
| 98 | +The namespace and name of the model is in the format of `<name>:<tag>`, which defines Models as OCI Artifacts in Docker Hub, therefore the namespace is the organization and the name is the repository. |
| 99 | + |
| 100 | +E.g. `ai/smollm2:360M-Q4_K_M`. See [Models as OCI Artifacts](https://hub.docker.com/u/ai) for more information. |
| 101 | + |
| 102 | +#### ListModels |
| 103 | + |
| 104 | +- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> |
| 105 | + |
| 106 | +Use the `ListModels` method to list all models that are already pulled locally, using the Docker Model Runner format. |
| 107 | + |
| 108 | +<!--codeinclude--> |
| 109 | +[Listing all models](../../modules/dockermodelrunner/examples_test.go) inside_block:runListModels |
| 110 | +<!--/codeinclude--> |
0 commit comments