[GH-ISSUE #5389] Add Basic Networking Tools to Docker Image for Health Checks #3370

Open
opened 2026-04-12 13:59:54 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @OlaoluwaM on GitHub (Jun 30, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/5389

Hi! Would it be possible to include one or two network command packages like ping, netcat, or curl in the Docker image? This would allow folks who want to query the health check endpoint using docker compose or similar tools to do so without needing to create a custom Dockerfile.

I get that y'all are hesitant about adding a HEALTHCHECK command directly to the Dockerfile since it's not standard in any of Docker's official images. But at least with these packages, anyone wanting to set up a health check for their containers can do so more easily.

I'd be happy to open a PR for this if you think it's a good idea.

Thanks!

Originally created by @OlaoluwaM on GitHub (Jun 30, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/5389 Hi! Would it be possible to include one or two network command packages like `ping`, `netcat`, or `curl` in the Docker image? This would allow folks who want to query the health check endpoint using `docker compose` or similar tools to do so without needing to create a custom `Dockerfile`. I get that y'all are [hesitant](https://github.com/ollama/ollama/pull/1909) about adding a `HEALTHCHECK` command directly to the Dockerfile since it's not standard in any of Docker's official images. But at least with these packages, anyone wanting to set up a health check for their containers can do so more easily. I'd be happy to open a PR for this if you think it's a good idea. Thanks!
GiteaMirror added the feature request label 2026-04-12 13:59:54 -05:00
Author
Owner

@rick-github commented on GitHub (Jun 30, 2024):

It's possible to add a health check to a docker-compose file. I use this for various docker images that don't contain in-image tools for testing endpoints, just set HEALTH for the port and pattern to check:

x-healthcheck: &healthcheck
  test: ["CMD-SHELL", "exec bash -c '
      for i in $${HEALTH-11434/:Ollama.is.running} ; do
        pat=$${i#*:} ;
        port=$${i%:*} ;
        path=$${port#*/} ;
        port=$${port%%/*} ;
        (exec 3<> /dev/tcp/localhost/$$port ;
        (echo GET /$$path HTTP/1.0 ; echo) >&3 ; cat <&3) | grep -q $$pat ||
          {
            [ $${RESTART-0} == 1 ] && { kill -s TERM -1 ; sleep 5 ; kill -s KILL -1 ; kill -s TERM 1 ; } ;
            exit 1 ;
          }
      done'"
    ]
  interval: 10s
  start_period: 10s

services:
  ollama:
    image: ollama/ollama
    healthcheck: *healthcheck
    environment:
      - HEALTH=11434/:Ollama.is.running

  litellm:
    image: litellm/litellm
    healthcheck: *healthcheck
    environment:
      - HEALTH=8000/health/liveliness:I.m.alive

<!-- gh-comment-id:2198503795 --> @rick-github commented on GitHub (Jun 30, 2024): It's possible to add a health check to a docker-compose file. I use this for various docker images that don't contain in-image tools for testing endpoints, just set HEALTH for the port and pattern to check: ``` x-healthcheck: &healthcheck test: ["CMD-SHELL", "exec bash -c ' for i in $${HEALTH-11434/:Ollama.is.running} ; do pat=$${i#*:} ; port=$${i%:*} ; path=$${port#*/} ; port=$${port%%/*} ; (exec 3<> /dev/tcp/localhost/$$port ; (echo GET /$$path HTTP/1.0 ; echo) >&3 ; cat <&3) | grep -q $$pat || { [ $${RESTART-0} == 1 ] && { kill -s TERM -1 ; sleep 5 ; kill -s KILL -1 ; kill -s TERM 1 ; } ; exit 1 ; } done'" ] interval: 10s start_period: 10s services: ollama: image: ollama/ollama healthcheck: *healthcheck environment: - HEALTH=11434/:Ollama.is.running litellm: image: litellm/litellm healthcheck: *healthcheck environment: - HEALTH=8000/health/liveliness:I.m.alive ```
Author
Owner

@sinanartun commented on GitHub (Jul 18, 2024):

you can just make a get request to /api/version

<!-- gh-comment-id:2236632516 --> @sinanartun commented on GitHub (Jul 18, 2024): you can just make a get request to /api/version
Author
Owner

@nopoz commented on GitHub (Oct 22, 2024):

See PR and temporary workaround for installing curl https://github.com/ollama/ollama/pull/6641#issuecomment-2430126710

<!-- gh-comment-id:2430130294 --> @nopoz commented on GitHub (Oct 22, 2024): See PR and temporary workaround for installing curl https://github.com/ollama/ollama/pull/6641#issuecomment-2430126710
Author
Owner

@rick-github commented on GitHub (Oct 22, 2024):

If users want to add tools to the docker image, just spin a new image:

FROM ollama/ollama                                                                                   
RUN apt update && apt install -y \
      curl \
      netcat \
      iputils-ping \
      && rm -rf /var/lib/apt/lists/*
$ docker build -f Dockerfile -t ollama-networktools .
$ docker run --rm -d --name ollama-networktools ollama-networktools
$ docker exec -it ollama-networktools curl localhost:11434
Ollama is running
<!-- gh-comment-id:2430253791 --> @rick-github commented on GitHub (Oct 22, 2024): If users want to add tools to the docker image, just spin a new image: ```Dockerfile FROM ollama/ollama RUN apt update && apt install -y \ curl \ netcat \ iputils-ping \ && rm -rf /var/lib/apt/lists/* ``` ``` $ docker build -f Dockerfile -t ollama-networktools . $ docker run --rm -d --name ollama-networktools ollama-networktools $ docker exec -it ollama-networktools curl localhost:11434 Ollama is running ```
Author
Owner

@qhaas commented on GitHub (Feb 21, 2025):

In docker compose (or your orchestration script of choice), could also just add a curl service (equivalent) that depends on ollama to check to see if it is up using the aforementioned api status call, e.g. (haven't tested, assuming the ollama service is named ollama)

```yaml
ollama-up:
    image: curlimages/curl
    command: -o /dev/null -kfsS ollama:11434/api/version
    restart: on-failure
    depends_on:
      - ollama

Note the above approach will not tell you if the ollama service later got into a bad state since it exits as soon as it succeeds.
I'm using a similar healthcheck inside the ollama container, but I installed curl in a derived image. The most annoying thing is the continuous spam in the ollama logs about the /api/version endpoint being hit by the healthcheck itself, which there is likely a way to disable and the use of a second curl service avoids.

<!-- gh-comment-id:2674924945 --> @qhaas commented on GitHub (Feb 21, 2025): In docker compose (or your orchestration script of choice), could also just add a curl [service (equivalent)](https://docs.docker.com/reference/compose-file/services/) that depends on ollama to check to see if it is up using the aforementioned api status call, e.g. (haven't tested, assuming the ollama service is named ollama) ``` ```yaml ollama-up: image: curlimages/curl command: -o /dev/null -kfsS ollama:11434/api/version restart: on-failure depends_on: - ollama ``` Note the above approach will not tell you if the ollama service later got into a bad state since it exits as soon as it succeeds. I'm using a similar healthcheck inside the ollama container, but I installed curl in a derived image. The most annoying thing is the continuous spam in the ollama logs about the /api/version endpoint being hit by the healthcheck itself, which there is likely a way to disable and the use of a second curl service avoids.
Author
Owner

@rick-github commented on GitHub (Feb 21, 2025):

Building on that, you could create an actual healthcheck that shows up in docker ps as healthy/unhealthy.

services:
  ollama:
    image: ollama/ollama

  ollama-up:
      image: curlimages/curl
      command: sleep inf
      healthcheck:
        test: curl ollama:11434
        interval: 5s
        start_period: 5s
      restart: on-failure
      depends_on:
        - ollama
<!-- gh-comment-id:2675055801 --> @rick-github commented on GitHub (Feb 21, 2025): Building on that, you could create an actual healthcheck that shows up in `docker ps` as healthy/unhealthy. ```yaml services: ollama: image: ollama/ollama ollama-up: image: curlimages/curl command: sleep inf healthcheck: test: curl ollama:11434 interval: 5s start_period: 5s restart: on-failure depends_on: - ollama ```
Author
Owner

@qhaas commented on GitHub (Feb 22, 2025):

That is a nice solution without having to modify the base image and still be able to check for bad state. Unfortunately, will still get a new log entry each time the healthcheck runs, which in some cases is ideal, but often is a bit too verbose.

<!-- gh-comment-id:2676312309 --> @qhaas commented on GitHub (Feb 22, 2025): That is a nice solution without having to modify the base image and still be able to check for bad state. Unfortunately, will still get a new log entry each time the healthcheck runs, which in some cases is ideal, but often is a bit too verbose.
Author
Owner

@rick-github commented on GitHub (Mar 15, 2025):

If docker compose is being used, here's a refinement to the new image workaround:

services:
  ollama:
    image: ollama-curl:${OLLAMA_DOCKER_TAG-latest}
    build:
      dockerfile_inline: |
        FROM ollama/ollama:${OLLAMA_DOCKER_TAG-latest}
        RUN apt update && apt install -y curl && rm -rf /var/lib/apt/lists/*
    healthcheck:
      test: curl ollama:11434
      interval: 5s
      start_period: 5s

This way there's no external Dockerfile to maintain.

<!-- gh-comment-id:2726457658 --> @rick-github commented on GitHub (Mar 15, 2025): If docker compose is being used, here's a refinement to the new image workaround: ```yaml services: ollama: image: ollama-curl:${OLLAMA_DOCKER_TAG-latest} build: dockerfile_inline: | FROM ollama/ollama:${OLLAMA_DOCKER_TAG-latest} RUN apt update && apt install -y curl && rm -rf /var/lib/apt/lists/* healthcheck: test: curl ollama:11434 interval: 5s start_period: 5s ``` This way there's no external Dockerfile to maintain.
Author
Owner

@rick-github commented on GitHub (Mar 17, 2025):

services:
  ollama:
    image: ollama/ollama:${OLLAMA_DOCKER_TAG-latest}
    environment:
      MODEL: ${MODEL-qwen2.5:0.5b}   # this model must always be present
    healthcheck:
      test: ollama show $${MODEL}
      interval: 60s
      start_period: 5s
<!-- gh-comment-id:2727768330 --> @rick-github commented on GitHub (Mar 17, 2025): ```yaml services: ollama: image: ollama/ollama:${OLLAMA_DOCKER_TAG-latest} environment: MODEL: ${MODEL-qwen2.5:0.5b} # this model must always be present healthcheck: test: ollama show $${MODEL} interval: 60s start_period: 5s ```
Author
Owner

@evrial commented on GitHub (Jul 12, 2025):

#11393 Fixes the issue in root

<!-- gh-comment-id:3065066904 --> @evrial commented on GitHub (Jul 12, 2025): #11393 Fixes the issue in root
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#3370