MCPcopy Index your code
hub / github.com/NVIDIA/libnvidia-container

github.com/NVIDIA/libnvidia-container @v1.19.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.19.1 ↗ · + Follow
689 symbols 1,852 edges 51 files 24 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

libnvidia-container

GitHub license GitHub release Package repository Travis Coverity Scan LGTM

This repository provides a library and a simple CLI utility to automatically configure GNU/Linux containers leveraging NVIDIA hardware.\ The implementation relies on kernel primitives and is designed to be agnostic of the container runtime.

Installing the library

From packages

Configure the package repository for your Linux distribution.

Install the packages:

libnvidia-container1
libnvidia-container-tools

From sources

With Docker:

# Generate docker images for a supported <os><version>
make {ubuntu18.04, ubuntu16.04, debian10, debian9, centos7, amazonlinux2, opensuse-leap15.1}

# Or generate docker images for all supported distributions in the dist/ directory
make docker
````

The resulting images have the name `nvidia/libnvidia-container/<os>:<version>`

Without Docker:
```bash
make install

# Alternatively in order to customize the installation paths
DESTDIR=/path/to/root make install prefix=/usr

Using the library

Container runtime example

Refer to the nvidia-container-runtime project.

Command line example

# Setup a new set of namespaces
cd $(mktemp -d) && mkdir rootfs
sudo unshare --mount --pid --fork

# Setup a rootfs based on Ubuntu 16.04 inside the new namespaces
curl http://cdimage.ubuntu.com/ubuntu-base/releases/16.04/release/ubuntu-base-16.04.6-base-amd64.tar.gz | tar -C rootfs -xz
useradd -R $(realpath rootfs) -U -u 1000 -s /bin/bash nvidia
mount --bind rootfs rootfs
mount --make-private rootfs
cd rootfs

# Mount standard filesystems
mount -t proc none proc
mount -t sysfs none sys
mount -t tmpfs none tmp
mount -t tmpfs none run

# Isolate the first GPU device along with basic utilities
nvidia-container-cli --load-kmods configure --ldconfig=@/sbin/ldconfig.real --no-cgroups --utility --device 0 $(pwd)

# Change into the new rootfs
pivot_root . mnt
umount -l mnt
exec chroot --userspec 1000:1000 . env -i bash

# Run nvidia-smi from within the container
nvidia-smi -L

Copyright and License

This project is released under the BSD 3-clause license.

Additionally, this project can be dynamically linked with libelf from the elfutils package (https://sourceware.org/elfutils), in which case additional terms apply.\ Refer to NOTICE for more information.

Issues and Contributing

Checkout the Contributing document!

Extension points exported contracts — how you extend this code

Interface (Interface)
(no doc) [2 implementers]
src/nvcgo/internal/cgroup/api.go

Core symbols most depended-on inside this repo

error_setx
called by 64
src/error_generic.c
error_set
called by 49
src/error_generic.c
xstrdup
called by 43
src/xfuncs.h
str_join
called by 33
src/utils.c
perm_set_capabilities
called by 30
src/utils.c
xmount
called by 23
src/xfuncs.h
path_resolve_full
called by 21
src/utils.c
xclose
called by 21
src/xfuncs.h

Shape

Class 309
Function 305
Enum 56
Method 14
Struct 4
Interface 1

Languages

C68%
C++27%
Go5%

Modules by API surface

src/nvml.h100 symbols
src/driver.c63 symbols
src/utils.c57 symbols
src/nvc_mount.c36 symbols
src/nvc_info.c36 symbols
src/dxcore.c28 symbols
src/cli/common.c26 symbols
src/cli/libnvc.c22 symbols
src/cli/configure.c21 symbols
src/nvc.c19 symbols
src/nvc_ldcache.c16 symbols
src/xfuncs.h15 symbols

For agents

$ claude mcp add libnvidia-container \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact