skip to Main Content

I have Ollama running in a Docker container that I spun up from the official image. I can successfully pull models in the container via interactive shell by typing commands at the command-line such as:

ollama pull nomic-embed-text

This command pulls in the model: nomic-embed-text.

Now I try to do the same via dockerfile:

FROM ollama/ollama

RUN ollama pull nomic-embed-text

# Expose port 11434
EXPOSE 11434

# Set the entrypoint
ENTRYPOINT ["ollama", "serve"]

and get

Error: could not connect to ollama app, is it running?
------
dockerfile:9
--------------------
   7 |     COPY . .
   8 |     
   9 | >>> RUN ollama pull nomic-embed-text
  10 |     
  11 |     # Expose port 11434
--------------------
ERROR: failed to solve: process "/bin/sh -c ollama pull nomic-embed-text" did not complete successfully: exit code: 1

As far as I know, I am doing the same thing but it works in one place and not another. Any help?

Based on the error message, I updated the dockerfile to launch the ollama service before pulling the model. No change.

FROM ollama/ollama

# Expose port 11434
EXPOSE 11434

RUN ollama serve &
RUN ollama pull nomic-embed-text

It gave same error message.

2

Answers


  1. Try this:

    Dockerfile:

    FROM ollama/ollama
    
    COPY ./run-ollama.sh /tmp/run-ollama.sh
    
    WORKDIR /tmp
    
    RUN chmod +x run-ollama.sh 
        && ./run-ollama.sh
    
    EXPOSE 11434
    

    run-ollama.sh:

    #!/usr/bin/env bash
    
    ollama serve &
    ollama list
    ollama pull nomic-embed-text
    
    ollama serve &
    ollama list
    ollama pull qwen:0.5b-chat
    
    Login or Signup to reply.
  2. Before pulling any model, Ollama needs to be running; otherwise, you won’t be able to pull any model. This simple workaround worked for me:

    #!/bin/bash
    
    echo "Starting Ollama server..."
    ollama serve &
    
    
    echo "Waiting for Ollama server to be active..."
    while [ "$(ollama list | grep 'NAME')" == "" ]; do
      sleep 1
    done
    
    
    ollama pull nomic-embed-text
    ollama pull phi3
    

    You can run that script from your Dockerfile

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search