/ .devops / llama-server-cuda.Dockerfile
llama-server-cuda.Dockerfile
 1  ARG UBUNTU_VERSION=22.04
 2  # This needs to generally match the container host's environment.
 3  ARG CUDA_VERSION=12.6.0
 4  # Target the CUDA build image
 5  ARG BASE_CUDA_DEV_CONTAINER=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION}
 6  # Target the CUDA runtime image
 7  ARG BASE_CUDA_RUN_CONTAINER=nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION}
 8  
 9  FROM ${BASE_CUDA_DEV_CONTAINER} AS build
10  
11  # CUDA architecture to build for (defaults to all supported archs)
12  ARG CUDA_DOCKER_ARCH=default
13  
14  RUN apt-get update && \
15      apt-get install -y build-essential git cmake libcurl4-openssl-dev
16  
17  WORKDIR /app
18  
19  COPY . .
20  
21  # Use the default CUDA archs if not specified
22  RUN if [ "${CUDA_DOCKER_ARCH}" != "default" ]; then \
23          export CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${CUDA_DOCKER_ARCH}"; \
24      fi && \
25      cmake -B build -DGGML_NATIVE=OFF -DGGML_CUDA=ON -DLLAMA_CURL=ON ${CMAKE_ARGS} -DCMAKE_EXE_LINKER_FLAGS=-Wl,--allow-shlib-undefined . && \
26      cmake --build build --config Release --target llama-server -j$(nproc) && \
27      mkdir -p /app/lib && \
28      find build -name "*.so" -exec cp {} /app/lib \;
29  
30  FROM ${BASE_CUDA_RUN_CONTAINER} AS runtime
31  
32  RUN apt-get update && \
33      apt-get install -y libcurl4-openssl-dev libgomp1 curl
34  
35  COPY --from=build /app/lib/ /
36  COPY --from=build /app/build/bin/llama-server /llama-server
37  
38  # Must be set to 0.0.0.0 so it can listen to requests from host machine
39  ENV LLAMA_ARG_HOST=0.0.0.0
40  
41  HEALTHCHECK CMD [ "curl", "-f", "http://localhost:8080/health" ]
42  
43  ENTRYPOINT [ "/llama-server" ]