-
Notifications
You must be signed in to change notification settings - Fork 5
/
Containerfile
58 lines (51 loc) · 3.66 KB
/
Containerfile
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
# **Description:**
# > IMPORTANT NOTE: This is BOOTC. This is meant for bootable container applications. See: https://github.com/containers/podman-desktop-extension-bootc
#
# This is a "base" container that installs the nvidia drivers and the nvidia container toolkit.
# This is meant to be used as a base for other containers that need GPU access.
#
# DISABLE SECURE BOOT! You have been warned! Disable boot is **KNOWN** to cause issues with the nvidia drivers.
# ENABLE 4G DECODING in the BIOS. This is needed for certain nvidia cards to work such as the Tesla P40.
#
# This Fedora 41 as the base image to (hopefully) be as stable as possible. Tried with Fedora 40 but found that the kernel was moving too fast
# for the nvidia drivers to keep up / work properly / update correctly.
#
# IMPORTANT NOTE:
# ANOTHER important note!!! Older cards such as the tesla p40 MAY not work because of the drivers being "too new" I had multiple issues with the p40 and the drivers. But no problems with rtx 3060 I have...
#
# On boot, this will **not** have the nvidia drivers loaded it they are compiled. This is because akmods are suppose to be built on boot, but this doesn't work with bootc.
# Instead, the nvidia drivers will recompile + use akmod + modprobe on boot.. and may take a minute to load.
# If you have any systemd services that require the nvidia drivers, you will need to add a `After=nvidia-drivers.service` to the service or have it LATE in the boot order (ex. multi-user.target)
# to ensure that the nvidia drivers are loaded before the service starts.
#
# For example, if you have a podman container with --restart=always, you will need to add a `After=nvidia-drivers.service` to the podman-restart.service and podman-restart.timer. file.
# This has been done for you already within the nvidia-drivers.service and nvidia-toolkit-firstboot.service files.
#
# Note about nvidia-toolkit-fristboot.service file: This is a one-time service on boot that will create the /etc/cdi/nvidia.yaml file. This is necessary for podman
# to use gpu devices.
#
#
# **Running:**
# 1. In your OTHER Containerfile, change to `FROM git.k8s.land/cdrage/bootc-nvidia-base-centos` / this Containerfile.
# 2. The nvidia drivers will recompile + use akmod + modprobe on boot.
# 3. Use nvidia-smi command within the booted container image to see if it works.
FROM quay.io/fedora/fedora-bootc:41
#! Install rpmfusion free and nonfree repo's for access to the nvidia drivers
RUN dnf install -y https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
RUN dnf install -y https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
#! Install the kernel devel and kernel header tools
#! We get the kernel that is being used in THE BASE IMAGE by doing /usr/lib/modules && echo *, then we install the kernel-devel for that kernel
#! SOMETIMES this messes up if the "base" image has an outdated kernel vs the one you get from dnf
RUN export KVER=$(cd /usr/lib/modules && echo *) && \
dnf install -y kernel-devel-$KVER
#! Install the nvidia drivers
RUN dnf install -y akmod-nvidia xorg-x11-drv-nvidia-cuda
#! Install NVIDIA container toolkit
RUN curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | tee /etc/yum.repos.d/nvidia-container-toolkit.repo && \
dnf install -y nvidia-container-toolkit
#! Blacklist the nouveau driver to ensure NVIDIA drivers function properly
RUN echo "blacklist nouveau" > /etc/modprobe.d/blacklist_nouveau.conf
#! Copy necessary usr files
COPY usr/ /usr/
#! Enable necessary services to be started at boot
RUN systemctl enable nvidia-toolkit-firstboot.service nvidia-drivers.service nvidia-persist.service