-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhypervisor-nvidia-rpmfusion.Containerfile
More file actions
69 lines (57 loc) · 3.01 KB
/
hypervisor-nvidia-rpmfusion.Containerfile
File metadata and controls
69 lines (57 loc) · 3.01 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
ARG BASE=ghcr.io/bensmith/hypervisor-bootc:latest
ARG BASE_DIGEST=""
# Stage 1: Build the NVIDIA kernel module RPM
FROM ${BASE}${BASE_DIGEST:+@${BASE_DIGEST}} AS kmod-builder
RUN dnf install -y \
https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
RUN KERNEL_VERSION=$(rpm -q kernel --qf '%{version}-%{release}.%{arch}\n' | tail -1) && \
dnf install --setopt=install_weak_deps=False -y \
akmod-nvidia \
"kernel-devel-${KERNEL_VERSION}" && \
dnf clean all
RUN mkdir -p /var/log/akmods && \
chmod 1777 /tmp /var/tmp && \
KERNEL_VERSION=$(rpm -q kernel --qf '%{version}-%{release}.%{arch}\n' | tail -1) && \
akmods --force --kernels "${KERNEL_VERSION}" && \
find /var/cache/akmods -name '*.rpm' | tee /dev/stderr | grep -q . || \
{ find /var/cache/akmods -name '*.failed.log' -exec cat {} +; exit 1; }
# Stage 2: Final bootc image
FROM ${BASE}${BASE_DIGEST:+@${BASE_DIGEST}}
# Add RPMFusion repositories for NVIDIA proprietary drivers
RUN dnf install -y \
https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
# Add NVIDIA official container toolkit repository
RUN curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | \
sed '/^sslcacert=/d' | \
tee /etc/yum.repos.d/nvidia-container-toolkit.repo
# Install NVIDIA drivers and tools, headless
RUN dnf install --setopt=install_weak_deps=False -y \
nvidia-container-toolkit \
nvidia-gpu-firmware \
nvidia-modprobe \
nvidia-persistenced \
xorg-x11-drv-nvidia \
xorg-x11-drv-nvidia-cuda \
xorg-x11-drv-nvidia-cuda-libs \
xorg-x11-drv-nvidia-libs && \
dnf clean all && \
rm -rf /var/log/* /var/cache/* /var/lib/dnf/* /boot/*
# Install pre-built kmod RPM from builder stage
COPY --from=kmod-builder /var/cache/akmods/ /tmp/akmods/
RUN find /tmp/akmods -name '*.rpm' -exec rpm -ivh {} + && \
rm -rf /tmp/akmods
# Blacklist nouveau and configure proprietary driver for KMS/Wayland
RUN echo -e "blacklist nouveau\noptions nouveau modeset=0" \
> /etc/modprobe.d/blacklist-nouveau.conf && \
echo -e "options nvidia-drm modeset=1 fbdev=1\noptions nvidia NVreg_PreserveVideoMemoryAllocations=1" \
> /etc/modprobe.d/nvidia-kms.conf
# Generate CDI specification for nvidia-container-toolkit (modern approach for podman/crun)
# Install service to generate CDI spec on first boot
COPY systemd/nvidia-cdi-generator.service /etc/systemd/system/nvidia-cdi-generator.service
RUN systemctl enable nvidia-persistenced && \
systemctl enable nvidia-cdi-generator.service && \
bootc container lint
LABEL org.opencontainers.image.title="Hypervisor Bootc Image - NVIDIA (RPMFusion)"
LABEL org.opencontainers.image.description="Bootc-based hypervisor with NVIDIA GPU support via RPMFusion"