-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
51 lines (46 loc) · 2.17 KB
/
dockerfile
File metadata and controls
51 lines (46 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
FROM ollama/ollama:0.17.7
# Preload specific models
ARG MODELS
ENV MODELS=${MODELS}
# needed to set in the environment
ARG OLLAMA_KEEP_ALIVE
ENV OLLAMA_KEEP_ALIVE=${OLLAMA_KEEP_ALIVE:-24h}
# Pre-pull models at build time for Docker layer caching
ARG TARGETARCH
RUN if [ -z "${MODELS:-}" ]; then \
echo "MODELS is empty; skipping build-time pre-pull."; \
else \
case "${TARGETARCH:-}" in \
amd64) PORT=11434 ;; \
arm64) PORT=11435 ;; \
*) PORT=11436 ;; \
esac; \
export OLLAMA_HOST="http://127.0.0.1:${PORT}"; \
ollama serve >/tmp/ollama-serve.log 2>&1 & pid="$!"; \
ready=0; \
for i in 1 2 3 4 5 6 7 8 9 10; do \
if ollama list >/dev/null 2>&1; then \
ready=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$ready" -ne 1 ]; then \
echo "ERROR: ollama did not become ready during build-time pre-pull" >&2; \
echo "--- /tmp/ollama-serve.log ---" >&2; \
cat /tmp/ollama-serve.log >&2 || true; \
kill "$pid" || true; \
wait "$pid" || true; \
exit 1; \
fi; \
for m in $MODELS; do \
echo "Pulling model $m..."; \
ollama pull "$m" || exit 1; \
done; \
kill "$pid"; \
wait "$pid" || true; \
fi
# Expose Ollama default port
EXPOSE 11434
# On container start, quickly ensure models exist (no re-download unless missing)
ENTRYPOINT ["/bin/bash", "-lc", "set -euo pipefail; if [[ -n \"${MODELS:-}\" ]]; then read -r -a models <<< \"${MODELS}\"; ollama serve >/tmp/ollama-entrypoint.log 2>&1 & pid=$!; ready=0; for i in {1..20}; do if ollama list >/dev/null 2>&1; then ready=1; break; fi; sleep 1; done; if [[ \"$ready\" -ne 1 ]]; then echo 'ERROR: ollama did not become ready during entrypoint pre-pull' >&2; echo '--- /tmp/ollama-entrypoint.log ---' >&2; cat /tmp/ollama-entrypoint.log >&2 || true; kill \"$pid\" || true; wait \"$pid\" || true; exit 1; fi; for m in \"${models[@]}\"; do ollama list | grep -qw \"$m\" || ollama pull \"$m\"; done; kill \"$pid\"; wait \"$pid\" || true; fi; exec ollama serve"]