seriffic commited on
Commit
b609855
·
1 Parent(s): 8e9301a

Dockerfile: don't pkill ollama in build (matched parent shell, exit 143)

Browse files

`pkill -f "ollama serve"` was matching the parent shell's command
line (since the RUN step itself contains the substring), killing the
build with SIGTERM and exit 143. Switch to capturing the daemon PID
explicitly and `kill $PID`. Also wait the daemon out properly
instead of the optimistic sleep.

Files changed (1) hide show
  1. Dockerfile +12 -4
Dockerfile CHANGED
@@ -45,13 +45,21 @@ RUN pip install --no-cache-dir --upgrade pip && \
45
  # Pull Granite 4.1:3b into the image. The official Ollama installer
46
  # stores models under /usr/share/ollama/.ollama by default; we point at a
47
  # user-writable location so the runtime container can also serve.
 
 
 
 
 
48
  ENV OLLAMA_MODELS=/home/user/.ollama/models
49
  RUN mkdir -p $OLLAMA_MODELS && \
50
- (ollama serve &) && \
51
- sleep 3 && \
 
 
 
 
52
  ollama pull granite4.1:3b && \
53
- sleep 1 && \
54
- pkill -f "ollama serve" || true
55
 
56
  # App code + fixtures
57
  COPY --chown=user:user app/ ./app/
 
45
  # Pull Granite 4.1:3b into the image. The official Ollama installer
46
  # stores models under /usr/share/ollama/.ollama by default; we point at a
47
  # user-writable location so the runtime container can also serve.
48
+ #
49
+ # Pattern: start ollama serve in the background, poll its HTTP endpoint
50
+ # until it answers, then pull the model. We do NOT kill the daemon at the
51
+ # end — the RUN shell's exit reaps it automatically, and `pkill -f` would
52
+ # match this RUN command line itself (SIGTERM propagates up, build exits 143).
53
  ENV OLLAMA_MODELS=/home/user/.ollama/models
54
  RUN mkdir -p $OLLAMA_MODELS && \
55
+ ollama serve > /tmp/ollama.log 2>&1 & \
56
+ for i in $(seq 1 60); do \
57
+ curl -sf http://127.0.0.1:11434/ > /dev/null 2>&1 && break; \
58
+ sleep 1; \
59
+ done && \
60
+ ollama list && \
61
  ollama pull granite4.1:3b && \
62
+ ollama list
 
63
 
64
  # App code + fixtures
65
  COPY --chown=user:user app/ ./app/