Skip to content

Commit 7d01be2

Browse files
committed
Enable GPU if available in Makefile
Also some podman-compatibility fixes, trying to compare why GPU access works in podman and not docker and vice versa for debugging reasons. Also, make "docker run" a shell script, mainly so we can run shellcheck on it. Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent 3886d0f commit 7d01be2

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
ARG GO_VERSION=1.24.2
44
ARG LLAMA_SERVER_VERSION=latest
55
ARG LLAMA_SERVER_VARIANT=cpu
6+
ARG TARGETARCH=${BUILDARCH}
67
ARG LLAMA_BINARY_PATH=/com.docker.llama-server.native.linux.${LLAMA_SERVER_VARIANT}.${TARGETARCH}
78
ARG BASE_IMAGE=ubuntu:24.04
89

9-
FROM golang:${GO_VERSION}-bookworm AS builder
10+
FROM docker.io/library/golang:${GO_VERSION}-bookworm AS builder
1011

1112
# Install git for go mod download if needed
1213
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
@@ -33,7 +34,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
3334
FROM docker/docker-model-backend-llamacpp:${LLAMA_SERVER_VERSION}-${LLAMA_SERVER_VARIANT} AS llama-server
3435

3536
# --- Final image ---
36-
FROM ${BASE_IMAGE} AS final
37+
FROM docker.io/${BASE_IMAGE} AS final
3738

3839
ARG LLAMA_SERVER_VARIANT
3940

Makefile

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,7 @@ docker-run: docker-build
5050
@echo "Service will be available at: http://localhost:$(PORT)"
5151
@echo "Example usage: curl http://localhost:$(PORT)/models"
5252
@echo ""
53-
mkdir -p $(MODELS_PATH)
54-
docker run --rm \
55-
-p $(PORT):$(PORT) \
56-
-v "$(MODELS_PATH):/models" \
57-
-e MODEL_RUNNER_PORT=$(PORT) \
58-
-e LLAMA_SERVER_PATH=/app/bin \
59-
-e MODELS_PATH=/models \
60-
-e LLAMA_ARGS="$(LLAMA_ARGS)" \
61-
-e DMR_ORIGINS="$(DMR_ORIGINS)" \
62-
-e DO_NOT_TRACK=${DO_NOT_TRACK} \
63-
-e DEBUG=${DEBUG} \
64-
$(DOCKER_IMAGE)
53+
scripts/docker-run.sh
6554

6655
# Show help
6756
help:

scripts/docker-run.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
main() {
4+
set -eux -o pipefail
5+
6+
local gpu_device_flag=("")
7+
for i in /dev/dri /dev/kfd; do
8+
if [ -e "$i" ]; then
9+
gpu_device_flag+=("--device" "$i")
10+
fi
11+
done
12+
13+
mkdir -p "$MODELS_PATH"
14+
chmod a+rx "$MODELS_PATH"
15+
docker run --rm \
16+
-p "$PORT:$PORT" \
17+
-v "$MODELS_PATH:/models" \
18+
-e MODEL_RUNNER_PORT="$PORT" \
19+
-e LLAMA_SERVER_PATH=/app/bin \
20+
-e MODELS_PATH=/models \
21+
-e LLAMA_ARGS="$LLAMA_ARGS" \
22+
-e DMR_ORIGINS="$DMR_ORIGINS" \
23+
-e DO_NOT_TRACK="$DO_NOT_TRACK" \
24+
-e DEBUG="$DEBUG" \
25+
--gpus all \
26+
"${gpu_device_flag[@]}"
27+
"$DOCKER_IMAGE"
28+
}
29+
30+
main "$@"
31+

0 commit comments

Comments
 (0)