[GH-ISSUE #9859] creating ollama custom model using modelfile inside docker #6456

Closed
opened 2026-04-12 18:01:05 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @babu-kandyala on GitHub (Mar 18, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/9859

What is the issue?

i am trying to build docker image with custom model using modelfile(with param's) with ollama/ollama:0.6.0 as base image. below is the Dockerfile

Using base image

FROM ollama/ollama:0.6.0

Adding an unprivileged user

RUN groupadd --gid 10001 ollama &&
useradd --uid 10001 --gid ollama --shell /bin/bash --create-home ollama

Change the ownership to ollama and provide necessary permissions

RUN chown -R ollama:ollama /bin/ollama && chmod 755 /bin/ollama

COPY modelfile modelfile

Create custom model

RUN ollama -v
RUN ollama serve &
RUN ollama run llama3.2
RUN ollama create ollama_custom -f modelfile

Make port 11434 available to the world outside this container

EXPOSE 11434

Run with no admin user

USER 10001

Run the custom model

CMD ["ollama", "run", "my_custom_model", "what is 2+2=? and say jonny jonny yes papa poem"]

docker build is failing with below error

#11 ERROR: process "/bin/sh -c ollama run llama3.2" did not complete successfully: exit code: 1

[7/8] RUN ollama run llama3.2:
0.174 Error: could not connect to ollama app, is it running?


Dockerfile:15

13 | RUN ollama -v
14 | RUN ollama serve &
15 | >>> RUN ollama run llama3.2
16 | RUN ollama create ollama_custom -f modelfile
17 |

ERROR: failed to solve: process "/bin/sh -c ollama run llama3.2" did not complete successfully: exit code: 1

Relevant log output


OS

Docker

GPU

AMD

CPU

AMD

Ollama version

0.6.0

Originally created by @babu-kandyala on GitHub (Mar 18, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/9859 ### What is the issue? i am trying to build docker image with custom model using modelfile(with param's) with ollama/ollama:0.6.0 as base image. below is the Dockerfile # Using base image FROM ollama/ollama:0.6.0 # Adding an unprivileged user RUN groupadd --gid 10001 ollama && \ useradd --uid 10001 --gid ollama --shell /bin/bash --create-home ollama # Change the ownership to ollama and provide necessary permissions RUN chown -R ollama:ollama /bin/ollama && chmod 755 /bin/ollama COPY modelfile modelfile # Create custom model RUN ollama -v RUN ollama serve & RUN ollama run llama3.2 RUN ollama create ollama_custom -f modelfile # Make port 11434 available to the world outside this container EXPOSE 11434 # Run with no admin user USER 10001 # Run the custom model CMD ["ollama", "run", "my_custom_model", "what is 2+2=? and say jonny jonny yes papa poem"] docker build is failing with below error #11 ERROR: process "/bin/sh -c ollama run llama3.2" did not complete successfully: exit code: 1 ------ > [7/8] RUN ollama run llama3.2: 0.174 Error: could not connect to ollama app, is it running? ------ Dockerfile:15 -------------------- 13 | RUN ollama -v 14 | RUN ollama serve & 15 | >>> RUN ollama run llama3.2 16 | RUN ollama create ollama_custom -f modelfile 17 | -------------------- ERROR: failed to solve: process "/bin/sh -c ollama run llama3.2" did not complete successfully: exit code: 1 ### Relevant log output ```shell ``` ### OS Docker ### GPU AMD ### CPU AMD ### Ollama version 0.6.0
GiteaMirror added the question label 2026-04-12 18:01:05 -05:00
Author
Owner

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

# Create custom model
RUN ollama serve & server=$! ; sleep 2 ; ollama pull llama3.2 ; ollama create ollama_custom -f modelfile ; kill $server
# Run the custom model
ENTRYPOINT [ "/bin/bash", "-c", "(sleep 2 ; ollama run ollama_custom '') & exec /bin/ollama $0" ]
CMD [ "serve" ]
<!-- gh-comment-id:2733976464 --> @rick-github commented on GitHub (Mar 18, 2025): ```dockerfile # Create custom model RUN ollama serve & server=$! ; sleep 2 ; ollama pull llama3.2 ; ollama create ollama_custom -f modelfile ; kill $server # Run the custom model ENTRYPOINT [ "/bin/bash", "-c", "(sleep 2 ; ollama run ollama_custom '') & exec /bin/ollama $0" ] CMD [ "serve" ] ```
Author
Owner

@pdevine commented on GitHub (Mar 18, 2025):

Going to close this as answered (thanks @rick-github !)

<!-- gh-comment-id:2734624817 --> @pdevine commented on GitHub (Mar 18, 2025): Going to close this as answered (thanks @rick-github !)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#6456