A straightforward guide to setting up and using Nvidia Container Builder (CB) to build and push custom Docker images for multi-architecture systems

Varun
3 min readJul 12, 2024

--

This guide will assist users in setting up CB, testing a sample build for x86 or aarch64, and pushing the final image to their own custom registry. The main advantage of CB is that users can build GPU-based aarch64 images on dGPUs, significantly reducing build time. Additionally, CB eliminates the need for maintaining separate Dockerfiles for different architectures, as it is managed by a single YML config file.

Step 1: Install NGC CLI (Optional but recommended if you are working with base images from NGC)

Click on the following link and select your host system type https://org.ngc.nvidia.com/setup/installers/cli. For example if you have an x86–64 Linux based system, you can follow the steps given at the end of the same page.

wget --content-disposition https://api.ngc.nvidia.com/v2/resources/nvidia/ngc-apps/ngc_cli/versions/3.44.0/files/ngccli_linux.zip -O ngccli_linux.zip && unzip ngccli_linux.zip
find ngc-cli/ -type f -exec md5sum {} + | LC_ALL=C sort | md5sum -c ngc-cli.md5
sha256sum ngccli_linux.zip
chmod u+x ngc-cli/ngc
echo "export PATH=\"\$PATH:$(pwd)/ngc-cli\"" >> ~/.bash_profile && source ~/.bash_profile
ngc config set

The last command prompts you to enter an API key that you can obtain from https://ngc.nvidia.com/setup/api-key. Once this is done, you’re ready to setup CB and Graph Compos.

Step 2: Setup CB and Graph Compose

Install Docker (Assuming a Linux system)

sudo apt-get update

sudo apt-get install ca-certificates curl

sudo install -m 0755 -d /etc/apt/keyrings

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Install Graph Compose (Assuming a Linux system)

Visit link https://catalog.ngc.nvidia.com/orgs/nvidia/resources/gxf_and_gc and download the graph compose deb file as well as the graph compose runtime file, and run the following commands

sudo apt install libyaml-cpp-dev
sudo dpkg -i graph_composer-runtime-4.0.0_x86_64.deb
sudo dpkg -i graph_composer-4.0.0_x86_64.deb

Step 3: Run CB and Graph Compose

Open a terminal tab and run the following command to initialise GXF

gxf_server

Create a config.yml based on what application you want to run as a container and build the docker image. Sample attached below which helps you run a simple TF application in case you want to test and play around with the .yml file params.

---
target: x86 # optional, can be used during multi-arch build
unique_stage: newtestvarun # required, name must be unique
# base_image is required
base_image: "nvcr.io/nvidia/cuda:11.2.2-cudnn8-runtime-ubuntu20.04"
stage_model: clean_stage # Optional

# Install custom packages
apt_deps:
- curl
- ca-certificates
- tar
- python3
- python3-pip
- libboost-all-dev

# Install pip3 packages
pip3_deps:
- PyYAML>=5.4.1
- numpy
- tensorflow

# Copy local files to image
local_copy_files:
- src: "/home/varun-personal/cont_build/test_app.py"
dst: "/root/test_app.py"

# Clean up operations
custom_runs:
- "apt autoremove && ln -s /opt/nvidia/cuda/samples /samples"

# Specify WORKDIR
work_folder: /workspace/test/

# Specify ENV variables
env_list:
PATH: "/opt/nvidia/cuda/bin:$PATH"
LD_LIBRARY_PATH: "/opt/nvidia/cuda/lib64:$LD_LIBRARY_PATH"

# Specify ENTRYPOINT if needed
entrypoint: ["python3", "/root/test_app.py"]

# Container builder configuration
container_builder: main # name

# Docker build options
docker_build:
image_name: testregistry.registry.com:5000/gpu_test_app:latest
no_cache: true
squash: false

# Docker push to registry / cloud
docker_push:
- url: "testregistry.registry.com:5000/gpu_test_app:latest"
username: test
password: testpassword

Information on each of the above parameters is given here https://resources.nvidia.com/en-us-deepstream-get-started-with-graph-composer/

Build your image using the command below

container_builder build -c config.yml -d x86

Also you would need to make sure your registry details in the yml file are correct in order to push the image. Hope this was helpful!

--

--

Varun
Varun

Written by Varun

A novice here. In hopes of documenting a few things that I’m passionate about and would like maybe a few people to read and understand

No responses yet