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
Try this:
Dockerfile:
run-ollama.sh:
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:
You can run that script from your Dockerfile