Dockerfile 6.04 KB
Newer Older
1
ARG GOLANG_VERSION=1.22.5
2
ARG CMAKE_VERSION=3.22.1
3
# this CUDA_VERSION corresponds with the one specified in docs/gpu.md
4
ARG CUDA_VERSION=11.3.1
Daniel Hiltgen's avatar
Daniel Hiltgen committed
5
ARG ROCM_VERSION=6.1.2
Michael Yang's avatar
Michael Yang committed
6

7
8
9
10
11
# Copy the minimal context we need to run the generate scripts
FROM scratch AS llm-code
COPY .git .git
COPY .gitmodules .gitmodules
COPY llm llm
Michael Yang's avatar
Michael Yang committed
12

13
14
15
16
17
FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64
ARG CMAKE_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
18
19
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
20
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
21
ENV GOARCH amd64 
22
RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
23

24
FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64
25
26
27
ARG CMAKE_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
28
ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
29
30
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
31
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
32
ENV GOARCH arm64 
33
RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
34

Daniel Hiltgen's avatar
Daniel Hiltgen committed
35
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
36
37
38
39
40
ARG CMAKE_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV LIBRARY_PATH /opt/amdgpu/lib64
41
42
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
43
44
ARG CGO_CFLAGS
ARG AMDGPU_TARGETS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
45
ENV GOARCH amd64 
46
RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
Daniel Hiltgen's avatar
Daniel Hiltgen committed
47
48
RUN mkdir -p ../../dist/linux-amd64/ollama_libs && \
    (cd /opt/rocm/lib && tar cf - rocblas/library) | (cd ../../dist/linux-amd64/ollama_libs && tar xf - )
49

50
FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64
51
52
53
54
55
ARG CMAKE_VERSION
ARG GOLANG_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
56
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
57
58
ARG OLLAMA_CUSTOM_CPU_DEFS
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
59
ENV GOARCH amd64 
60
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
61

62
63
FROM --platform=linux/amd64 cpu-builder-amd64 AS static-build-amd64
RUN OLLAMA_CPU_TARGET="static" sh gen_linux.sh
64
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
65
RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
66
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
67
RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx" sh gen_linux.sh
68
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
69
RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx2" sh gen_linux.sh
70

71
FROM --platform=linux/arm64 rockylinux:8 AS cpu-builder-arm64
72
73
74
75
ARG CMAKE_VERSION
ARG GOLANG_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
76
ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
77
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
78
79
ARG OLLAMA_CUSTOM_CPU_DEFS
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
80
ENV GOARCH arm64
81
82
83
84
85
WORKDIR /go/src/github.com/ollama/ollama/llm/generate

FROM --platform=linux/arm64 cpu-builder-arm64 AS static-build-arm64
RUN OLLAMA_CPU_TARGET="static" sh gen_linux.sh
FROM --platform=linux/arm64 cpu-builder-arm64 AS cpu-build-arm64
86
RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
87

88

89
90
91
# Intermediate stage used for ./scripts/build_linux.sh
FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64
ENV CGO_ENABLED 1
92
WORKDIR /go/src/github.com/ollama/ollama
93
COPY . .
94
95
96
COPY --from=static-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
COPY --from=cpu_avx-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
COPY --from=cpu_avx2-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
Daniel Hiltgen's avatar
Daniel Hiltgen committed
97
COPY --from=cuda-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
98
COPY --from=cuda-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
Daniel Hiltgen's avatar
Daniel Hiltgen committed
99
COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
100
COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
101
102
ARG GOFLAGS
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
103
RUN go build -trimpath -o dist/linux-amd64/ollama .
Michael Yang's avatar
Michael Yang committed
104

105
106
107
108
# Intermediate stage used for ./scripts/build_linux.sh
FROM --platform=linux/arm64 cpu-build-arm64 AS build-arm64
ENV CGO_ENABLED 1
ARG GOLANG_VERSION
109
WORKDIR /go/src/github.com/ollama/ollama
Jeffrey Morgan's avatar
Jeffrey Morgan committed
110
COPY . .
111
COPY --from=static-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
Daniel Hiltgen's avatar
Daniel Hiltgen committed
112
COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/dist/ dist/
113
COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
114
115
ARG GOFLAGS
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
116
RUN go build -trimpath -o dist/linux-arm64/ollama .
Jeffrey Morgan's avatar
Jeffrey Morgan committed
117

118
# Runtime stages
Daniel Hiltgen's avatar
Daniel Hiltgen committed
119
120
FROM --platform=linux/amd64 ubuntu:22.04 as runtime-amd64
RUN apt-get update && apt-get install -y ca-certificates
Daniel Hiltgen's avatar
Daniel Hiltgen committed
121
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/dist/linux-amd64/ollama /bin/ollama
122
FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64
Michael Yang's avatar
Michael Yang committed
123
RUN apt-get update && apt-get install -y ca-certificates
Daniel Hiltgen's avatar
Daniel Hiltgen committed
124
COPY --from=build-arm64 /go/src/github.com/ollama/ollama/dist/linux-arm64/ollama /bin/ollama
125

126
# Radeon images are much larger so we keep it distinct from the CPU/CUDA image
Daniel Hiltgen's avatar
Daniel Hiltgen committed
127
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete as runtime-rocm
128
RUN update-pciids
Daniel Hiltgen's avatar
Daniel Hiltgen committed
129
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/dist/linux-amd64/ollama /bin/ollama
130
131
132
133
134
135
EXPOSE 11434
ENV OLLAMA_HOST 0.0.0.0

ENTRYPOINT ["/bin/ollama"]
CMD ["serve"]

136
FROM runtime-$TARGETARCH
137
138
EXPOSE 11434
ENV OLLAMA_HOST 0.0.0.0
139
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
140
ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
141
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
142
ENV NVIDIA_VISIBLE_DEVICES=all
143

Jeffrey Morgan's avatar
Jeffrey Morgan committed
144
ENTRYPOINT ["/bin/ollama"]
Jeffrey Morgan's avatar
Jeffrey Morgan committed
145
CMD ["serve"]