From bd8fc13d7fd45414198e87ac92f9af51f57f16de Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Thu, 11 Jul 2019 02:44:17 +0300 Subject: [PATCH 1/6] patch.sh: add custom output dir; get rid of `which` binary dependency --- patch.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patch.sh b/patch.sh index 21eaa2b..f2c2bcd 100755 --- a/patch.sh +++ b/patch.sh @@ -95,7 +95,7 @@ declare -A object_list=( ["430.34"]='libnvcuvid.so' ) -NVIDIA_SMI="$(which nvidia-smi)" +NVIDIA_SMI="$(command -v nvidia-smi)" if ! driver_version=$("$NVIDIA_SMI" --query-gpu=driver_version --format=csv,noheader,nounits | head -n 1) ; then echo 'Something went wrong. Check nvidia driver' @@ -151,8 +151,8 @@ else fi sha1sum "$backup_path/$object.$driver_version" sed "$patch" "$backup_path/$object.$driver_version" > \ - "$driver_dir/$object.$driver_version" - sha1sum "$driver_dir/$object.$driver_version" + "${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version" + sha1sum "${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version" ldconfig echo "Patched!" fi From d34338ba70d04bcfd099f79360ffc4d186cc95cb Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Thu, 11 Jul 2019 02:56:31 +0300 Subject: [PATCH 2/6] added dockerfile and docker entrypoint script --- Dockerfile | 7 +++++++ docker-entrypoint.sh | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..01748c8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM nvidia/cuda:latest + +RUN mkdir -p /usr/local/bin /patched-lib +COPY patch.sh docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/patch.sh /usr/local/bin/docker-entrypoint.sh + +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..4e83878 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +echo "/patched-lib" > /etc/ld.so.conf.d/000-patched-lib.conf && \ +PATCH_OUTPUT_DIR=/patched-lib /usr/local/bin/patch.sh && \ +cd /patched-lib && \ +for f in * ; do + suffix="${f##*.so}" + name="$(basename "$f" "$suffix")" + ln -s "$f" "$name" + ln -s "$f" "$name.1" +done && \ +ldconfig +[ "$OLDPWD" ] && cd - +exec "$@" From 65b733f3f7838ed1d332c5fda7bde681cbf3e8e7 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Thu, 11 Jul 2019 03:11:15 +0300 Subject: [PATCH 3/6] docs: docker support --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 01335b9..16a57ba 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,17 @@ If something got broken you may restore patched driver from backup: bash ./patch.sh -r ``` +## Docker support + +It is possible to use this patch with nvidia-docker containers, even if host machine hasn't patched drivers. See `Dockerfile` for example. + +Essentially all you need to do during build is: + +* `COPY` the `patch.sh` and `docker-entrypoint.sh` files into your container. +* Make sure `docker-entrypoint.sh` is invoked on container start. + +`docker-entrypoint.sh` script does on-the-fly patching by means of manipulating dynamic linker to workaround read-only mount of Nvidia runtime. Finally it passes original docker command to shell, like if entrypoint was not restricted by `ENTRYPOINT` directive. So `docker run --runtime=nvidia -it mycontainer echo 123` will print `123`. Also it can be just invoked from your entrypoint script, if you have any. + ## See also * Plex Media Server: enable HW **decoding**: From 94222a882455d571d94aad6c1512cba3eebff0fd Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Thu, 11 Jul 2019 03:16:57 +0300 Subject: [PATCH 4/6] docker-entrypoint: do not symlink if there is already one; force if there is not --- docker-entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4e83878..f6e0904 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -6,8 +6,8 @@ cd /patched-lib && \ for f in * ; do suffix="${f##*.so}" name="$(basename "$f" "$suffix")" - ln -s "$f" "$name" - ln -s "$f" "$name.1" + [ -h "$name" ] || ln -sf "$f" "$name" + [ -h "$name" ] || ln -sf "$f" "$name.1" done && \ ldconfig [ "$OLDPWD" ] && cd - From 389235cd9203fb12a16d00610be3419ee1daffe8 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Thu, 11 Jul 2019 03:26:23 +0300 Subject: [PATCH 5/6] dockerfile: add some reasonable ENV defaults --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 01748c8..a1a65ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM nvidia/cuda:latest +ENV NVIDIA_VISIBLE_DEVICES all +ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility + RUN mkdir -p /usr/local/bin /patched-lib COPY patch.sh docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/patch.sh /usr/local/bin/docker-entrypoint.sh From 2958221d64ed2419dec5d7404759d985f247ca13 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Thu, 11 Jul 2019 03:31:01 +0300 Subject: [PATCH 6/6] docker-entrypoint: ensure output dir --- docker-entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index f6e0904..f70139a 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/sh echo "/patched-lib" > /etc/ld.so.conf.d/000-patched-lib.conf && \ +mkdir -p "/patched-lib" && \ PATCH_OUTPUT_DIR=/patched-lib /usr/local/bin/patch.sh && \ cd /patched-lib && \ for f in * ; do