"wget --no-verbose --tries=1 --spider localhost:7474 || exit 1",
]
interval: 5s
timeout: 3s
retries: 5
ollama:
image: ollama/ollama:latest
ports:
- "11434:11434"
volumes:
- ollama_volume:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
volumes:
ollama_volume:
```
> [!NOTE]
>
> For more details about the Compose instructions, see [Turn on GPU access with Docker Compose](/manuals/compose/how-tos/gpu-support.md).
3. Add the ollama-pull service to your `compose.yaml` file. This service uses
the `docker/genai:ollama-pull` image, based on the GenAI Stack's
[pull_model.Dockerfile](https://github.com/docker/genai-stack/blob/main/pull_model.Dockerfile).
The service will automatically pull the model for your Ollama
container. The following is the updated section of the `compose.yaml` file:
```yaml {hl_lines=["12-17"]}
services:
server:
build:
context: .
ports:
- 8000:8000
env_file:
- .env
depends_on:
database:
condition: service_healthy
ollama-pull:
condition: service_completed_successfully
ollama-pull:
image: docker/genai:ollama-pull
env_file:
- .env
# ...
```
{{< /tab >}}
{{< tab name="Run Ollama outside of a container" >}}
To run Ollama outside of a container:
1. [Install](https://github.com/jmorganca/ollama) and run Ollama on your host
machine.
2. Update the `OLLAMA_BASE_URL` value in your `.env` file to
`http://host.docker.internal:11434`.
3. Pull the model to Ollama using the following command.
```console
$ ollama pull llama2
```
{{< /tab >}}
{{< tab name="Use OpenAI" >}}
> [!IMPORTANT]
>
> Using OpenAI requires an [OpenAI account](https://platform.openai.com/login). OpenAI is a third-party hosted service and charges may apply.
1. Update the `LLM` value in your `.env` file to