From 1162d58e8c4e3a1b19a6e2ef10650c1c23022d8d Mon Sep 17 00:00:00 2001 From: Joey McDonald Date: Thu, 22 Feb 2024 13:18:01 -0700 Subject: [PATCH 1/6] Add docker-compose yaml file and README markdown --- examples/docker-compose/README.md | 41 +++++++++++++++++++++ examples/docker-compose/docker-compose.yaml | 18 +++++++++ 2 files changed, 59 insertions(+) create mode 100644 examples/docker-compose/README.md create mode 100644 examples/docker-compose/docker-compose.yaml diff --git a/examples/docker-compose/README.md b/examples/docker-compose/README.md new file mode 100644 index 00000000..1c9749e6 --- /dev/null +++ b/examples/docker-compose/README.md @@ -0,0 +1,41 @@ +# Ollama Service + +This Docker Compose setup deploys the Ollama service, using the main ollama image hosted on dockerhub. Ollama is designed to run seamlessly in a Docker environment, with health checks and volume management. + +## Prerequisites + +- Docker +- Docker Compose + +Ensure Docker and Docker Compose are installed and up-to-date on your system. + +## Configuration + +The service configuration is managed through the `docker-compose.yml` file and environment variables. You can customize the Ollama service port by setting the `OLLAMA_PORT` environment variable; if not set, it defaults to 11434. + +## Getting Started + +1. **Run:** To start the Ollama service run: +```bash + docker-compose up +``` + +2. **Build and Run:** To build the project and start the Ollama service, run: +```bash + docker-compose up --build +``` + +## NOTES: + +1. Health Check: The service includes a health check that verifies the application's ability to accept connections on port 11434 (or a custom port if OLLAMA_PORT is set). + +2. Accessing Ollama: Once running, Ollama is accessible on localhost at the port specified by OLLAMA_PORT or the default 11434. + +3. Volumes: To persist data, the setup mounts a volume from ./ollama to /root/.ollama within the container. + +4. Stopping the Service: To stop and remove the Ollama container, use: + +```bash + docker-compose down +``` + diff --git a/examples/docker-compose/docker-compose.yaml b/examples/docker-compose/docker-compose.yaml new file mode 100644 index 00000000..4298af8a --- /dev/null +++ b/examples/docker-compose/docker-compose.yaml @@ -0,0 +1,18 @@ +--- +version: "3.8" + +services: + ollama: + build: + context: ../.. + dockerfile: Dockerfile + container_name: ollama + image: ollama/ollama + healthcheck: + test: ["CMD-SHELL", "cat < /dev/null > /dev/tcp/localhost/11434 || exit 1"] + interval: 10s + ports: + - "${OLLAMA_PORT:-11434}:11434" + volumes: + - ./ollama:/root/.ollama + restart: on-failure From 5b11a9883ff3836f66fec2f01373fc1a7c791455 Mon Sep 17 00:00:00 2001 From: Joey McDonald Date: Thu, 22 Feb 2024 13:24:17 -0700 Subject: [PATCH 2/6] Add detach to run command --- examples/docker-compose/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/docker-compose/README.md b/examples/docker-compose/README.md index 1c9749e6..315e7ddd 100644 --- a/examples/docker-compose/README.md +++ b/examples/docker-compose/README.md @@ -17,7 +17,7 @@ The service configuration is managed through the `docker-compose.yml` file and e 1. **Run:** To start the Ollama service run: ```bash - docker-compose up + docker-compose up -d ``` 2. **Build and Run:** To build the project and start the Ollama service, run: From dc1e4e01152a4a156fadd8d9e70e1f6d5eae1b80 Mon Sep 17 00:00:00 2001 From: Joey McDonald Date: Thu, 22 Feb 2024 13:33:23 -0700 Subject: [PATCH 3/6] Account for port changes in the healthcheck --- examples/docker-compose/docker-compose.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/docker-compose/docker-compose.yaml b/examples/docker-compose/docker-compose.yaml index 4298af8a..7986cd43 100644 --- a/examples/docker-compose/docker-compose.yaml +++ b/examples/docker-compose/docker-compose.yaml @@ -1,15 +1,14 @@ ---- version: "3.8" services: ollama: build: context: ../.. - dockerfile: Dockerfile + dockerfile: Dockerfile container_name: ollama image: ollama/ollama healthcheck: - test: ["CMD-SHELL", "cat < /dev/null > /dev/tcp/localhost/11434 || exit 1"] + test: ["CMD-SHELL", "cat < /dev/null > /dev/tcp/localhost/${OLLAMA_PORT:-11434} || exit 1"] interval: 10s ports: - "${OLLAMA_PORT:-11434}:11434" From 9f2e6cf2781442ec07e177db549c60c478cbd8ac Mon Sep 17 00:00:00 2001 From: Joey McDonald Date: Thu, 22 Feb 2024 13:34:01 -0700 Subject: [PATCH 4/6] Fix filename typo in README.md --- examples/docker-compose/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/docker-compose/README.md b/examples/docker-compose/README.md index 315e7ddd..7ee53da2 100644 --- a/examples/docker-compose/README.md +++ b/examples/docker-compose/README.md @@ -11,7 +11,7 @@ Ensure Docker and Docker Compose are installed and up-to-date on your system. ## Configuration -The service configuration is managed through the `docker-compose.yml` file and environment variables. You can customize the Ollama service port by setting the `OLLAMA_PORT` environment variable; if not set, it defaults to 11434. +The service configuration is managed through the `docker-compose.yaml` file and environment variables. You can customize the Ollama service port by setting the `OLLAMA_PORT` environment variable; if not set, it defaults to 11434. ## Getting Started From 76a97b12467a82674653ea89f395f4c2ead57116 Mon Sep 17 00:00:00 2001 From: Joey McDonald Date: Fri, 15 Mar 2024 11:00:43 -0600 Subject: [PATCH 5/6] Update docker-compose healthcheck to use explicit bash path as requested by frob --- examples/docker-compose/docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/docker-compose/docker-compose.yaml b/examples/docker-compose/docker-compose.yaml index 7986cd43..0ffa19ff 100644 --- a/examples/docker-compose/docker-compose.yaml +++ b/examples/docker-compose/docker-compose.yaml @@ -8,7 +8,7 @@ services: container_name: ollama image: ollama/ollama healthcheck: - test: ["CMD-SHELL", "cat < /dev/null > /dev/tcp/localhost/${OLLAMA_PORT:-11434} || exit 1"] + test: ["CMD-SHELL", "/usr/bin/bash -c 'cat < /dev/null > /dev/tcp/localhost/${OLLAMA_PORT:-11434} || exit 1'"] interval: 10s ports: - "${OLLAMA_PORT:-11434}:11434" From b91c94d64a8e194ffbac9506e60116538c8c37ee Mon Sep 17 00:00:00 2001 From: Joey McDonald Date: Fri, 15 Mar 2024 12:17:24 -0600 Subject: [PATCH 6/6] Internal port never changes, so always use 11434 for health-checks --- examples/docker-compose/docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/docker-compose/docker-compose.yaml b/examples/docker-compose/docker-compose.yaml index 0ffa19ff..9b295f4a 100644 --- a/examples/docker-compose/docker-compose.yaml +++ b/examples/docker-compose/docker-compose.yaml @@ -8,7 +8,7 @@ services: container_name: ollama image: ollama/ollama healthcheck: - test: ["CMD-SHELL", "/usr/bin/bash -c 'cat < /dev/null > /dev/tcp/localhost/${OLLAMA_PORT:-11434} || exit 1'"] + test: ["CMD-SHELL", "/usr/bin/bash -c 'cat < /dev/null > /dev/tcp/localhost/11434 || exit 1'"] interval: 10s ports: - "${OLLAMA_PORT:-11434}:11434"