Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Short Bash script to enable use of the GPU within a docker container running on an NVIDIA Jetson TX2. Place inside /usr/local/bin/, chmod +x txdocker, ensure it is in your system PATH, and use just as you would the docker command.
#Jason T. 2-6-2018
# Check specifically for the run command
if [[ $# -ge 2 && $1 == "run" ]]; then
# Tell docker to share the following folders with the base system
# This allows the docker containers to find CUDA, cuDNN, TensorRT
LIB_MAPS="/usr/lib/aarch64-linux-gnu \
/usr/local/cuda \
# GPU device sharing is for a docker container to have access to
# system devices as found in the /dev directory
DEVICES="/dev/nvhost-ctrl \
/dev/nvhost-ctrl-gpu \
/dev/nvhost-prof-gpu \
/dev/nvmap \
/dev/nvhost-gpu \
# There is a need to map the libraries inside the container
# in the exact way programs would expect to find them as
# though the TX2 were operating without containers
for lib in $LIB_MAPS; do
LIBS="$LIBS -v $lib:$lib"
for dev in $DEVICES; do
DEVS="$DEVS --device=$dev"
#echo "docker run $LIBS $DEVS ${@:2}"
docker run $LIBS $DEVS ${@:2}
# Run command not found, run everything straight through docker
#echo "docker $@"
docker $@
Copy link

paghdv commented Oct 3, 2018

Can you mention what is the base image that you use in the Tx2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment