Curious Minds

Clear answers to science and history questions

How to Use GPUs in Containers on Bare Metal RHEL

· 6 min read · Science

To use GPUs in containers on bare-metal Red Hat Enterprise Linux, you install the NVIDIA driver on the RHEL host itself, add the NVIDIA Container Toolkit, then run containers with the --device and --gpus options (Docker) or CDI/device flags (Podman) so the container gets access to the host GPU. The key principle is simple: the driver lives on the host, and the container only receives the device nodes and user-space libraries it needs. RHEL is a common choice for this setup because it is what most enterprise GPU clusters and Red Hat OpenShift environments are built on.

Why the Driver Stays on the Host

A common misconception is that you can put the NVIDIA driver inside the container and keep the host "clean." In practice, the kernel module portion of the driver must match the running kernel, so it has to be loaded on the bare-metal host. The NVIDIA Container Toolkit solves the other half of the problem: it injects the matching user-space driver libraries and the device nodes (/dev/nvidia0, /dev/nvidiactl, /dev/nvidia-uvm) into the container at launch time. This is why a CUDA image from a registry works on many different hosts — the container ships the CUDA runtime, while the driver components come from the host.

Because you are on bare metal rather than a virtual machine, there is no GPU passthrough or vGPU licensing to worry about. The GPU is physically in the machine, and the only question is how to expose it to the container runtime safely.

Step-by-Step Setup on RHEL

  1. Verify the hardware: run lspci | grep -i nvidia to confirm the GPU is visible to the machine.
  2. Install the NVIDIA driver on RHEL. The supported route is the NVIDIA CUDA repository for RHEL (or the driver RPMs from NVIDIA's repository for your RHEL major version), installed with dnf. Third-party repositories like ELRepo also carry NVIDIA driver packages (kmod-nvidia). Reboot or load the modules, then confirm with nvidia-smi.
  3. Install a container runtime: Podman is included with RHEL; Docker can be installed separately if your tooling requires it.
  4. Install the NVIDIA Container Toolkit from NVIDIA's repository using dnf install nvidia-container-toolkit.
  5. Configure the runtime: for Docker run sudo nvidia-ctk runtime configure --runtime=docker and restart the Docker daemon. For Podman, generate a CDI spec with sudo nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml.
  6. Test with a CUDA container, for example podman run --rm --device nvidia.com/gpu=all docker.io/nvidia/cuda:12.4.0-base-ubi9 nvidia-smi (Docker equivalent: docker run --rm --gpus all nvidia/cuda:12.4.0-base-ubi9 nvidia-smi). If you see the GPU listed inside the container, the stack works.

Note that NVIDIA publishes CUDA container images based on Ubuntu and on Universal Base Image (UBI), which is Red Hat's own container base — the UBI-based images are the natural fit for RHEL environments.

Podman vs. Docker on RHEL

Podman is the default container engine on RHEL and is daemonless and rootless-capable, which matters for security on shared GPU servers. Docker uses a daemon and historically required root or group membership for socket access. Functionally, both work with the NVIDIA Container Toolkit; the difference is mostly in how GPU access is requested:

  • Docker: --gpus all or --gpus device=0 to select a specific card.
  • Podman: CDI device names such as --device nvidia.com/gpu=all or a specific device index, which also works rootless once permissions on the device nodes allow it.

If you are heading toward Kubernetes, be aware that Red Hat OpenShift uses the NVIDIA GPU Operator, which automates driver installation and device plugin deployment across a cluster — a different but related toolchain from the single-host approach described here.

Common Problems and Fixes

  • Kernel updates break the driver. After a RHEL kernel update, the NVIDIA kernel module may not load until the matching driver module is rebuilt or updated, and nvidia-smi fails on the host. Installing the driver from the kmod-style RPM packages (rather than the .run installer) lets dnf handle this more gracefully.
  • "could not select device driver" or "unknown capability" errors. Usually the toolkit is installed but the runtime was never reconfigured, or the daemon was not restarted. Re-run nvidia-ctk runtime configure and restart the runtime.
  • Driver/library version mismatch inside the container. This happens when the host driver is older than the CUDA version the image expects. Either update the host driver or pick a container image whose CUDA version is supported by it.
  • Rootless Podman cannot see the GPU. The user needs appropriate permissions on the NVIDIA device nodes; the CDI generation step includes an option to adjust device permissions for rootless use.
  • Secure Boot / signed modules. On systems with Secure Boot enabled, unsigned kernel modules will not load, so the driver must be installed with a signed module path supported for RHEL.

Sharing One GPU Across Containers

Multiple containers can share the same physical GPU, since each simply opens the same device nodes. This is convenient for running several inference or training jobs on one card, but there is no hard isolation of memory: one container that allocates all GPU memory starves the others. For stricter separation you can pin containers to specific GPUs on a multi-GPU machine (via --gpus device=1 or the CDI equivalent) or use CUDA MPS (Multi-Process Service) to improve sharing efficiency. NVIDIA's device plugin for Kubernetes handles GPU scheduling across pods, which is the managed way to do this at cluster scale.

Alternatives to the Container Route

  • Running GPU workloads directly on the RHEL host, installing CUDA and the application natively — simplest, but loses container portability and dependency isolation.
  • Red Hat OpenShift with the NVIDIA GPU Operator — the right answer once you have many nodes, since it automates drivers, toolkit, monitoring and scheduling.
  • Virtual machines with GPU passthrough — useful for isolating tenants, but unnecessary on a single-user bare-metal box and it adds configuration overhead.
  • Cloud GPU instances — the same container techniques apply, but the "bare metal" part is someone else's problem.

Frequently Asked Questions

Do I need to install CUDA on the RHEL host?

No. Only the NVIDIA driver is required on the host. The CUDA toolkit, cuDNN and other libraries come from the container image, which is one of the main benefits of the container approach — you can run different CUDA versions in different containers on the same machine.

Does this work with AMD GPUs too?

The concept is the same, but the tooling differs. AMD's ROCm stack provides its own container support, and Podman's CDI mechanism can expose AMD GPUs to containers. The NVIDIA Container Toolkit steps above apply specifically to NVIDIA hardware.

Can I run GPU containers without root?

Yes with Podman in rootless mode, provided the user has the necessary permissions on the GPU device nodes. Docker typically requires membership in a privileged group or root, which is one reason Podman is preferred on hardened RHEL servers.

What happens when RHEL updates the kernel?

The NVIDIA kernel module must match the running kernel, so after a kernel update the driver module may need rebuilding or updating before nvidia-smi works again. Using dnf-managed driver packages rather than the standalone .run installer makes this recovery much easier.

Is there a performance penalty for using GPUs in containers?

For compute workloads, the overhead is negligible — the container talks to the GPU through the same device nodes and driver the host uses. There is no emulation layer involved; it is essentially access control plus library injection.

Can one container use multiple GPUs?

Yes. With --gpus all or the CDI equivalent, all host GPUs are visible inside the container, and applications can select them via CUDA's device enumeration. You can also expose a specific subset.

In this article
  1. Why the Driver Stays on the Host
  2. Step-by-Step Setup on RHEL
  3. Podman vs. Docker on RHEL
  4. Common Problems and Fixes
  5. Sharing One GPU Across Containers
  6. Alternatives to the Container Route
  7. Frequently Asked Questions