Hack the Container: Understanding Docker's Inner Workings
Adding a New Runtime to Docker
It's possible to add new runtimes to Docker in addition to the default ones (runc and containerd). This is useful when you want to use a different low-level runtime or take advantage of specific features provided by another runtime. For example, if you're developing machine learning applications that require GPU access, you might want to add the NVIDIA container runtime to Docker. In the following example, we're going to show how to install this runtime:
# Install some prerequisites
apt-get update && apt-get install -y --no-install-recommends \
curl \
gnupg2
# Import the NVIDIA GPG key
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \
gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
# Update the repository list with signing
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Update packages and install the NVIDIA container toolkit
apt-get update && \
apt-get install -y nvidia-container-toolkit
After installing the runtime, you need to configure Docker to use it. You can do this by updating the daemon.json file located at /etc/docker/daemon.json. If the file doesn't exist, you can create it. Here is an example of how to add the NVIDIA runtime:
# export the runtime name
export RUNTIME="nvidia"
# export the runtime path
export RUNTIME_PATH="/usr/bin/nvidia-container-runtime"
# Update the daemon.json file or create it if it doesn't exist
tee /etc/docker/daemon.json <Painless Docker - 2nd Edition
A Comprehensive Guide to Mastering Docker and its EcosystemEnroll now to unlock all content and receive all future updates for free.
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
