Merge pull request #132 from Snawoot/docker

Docker support
This commit is contained in:
Snawoot 2019-07-11 03:32:22 +03:00 committed by GitHub
commit ee9dd84e76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 3 deletions

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
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
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

View File

@ -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**:

15
docker-entrypoint.sh Normal file
View File

@ -0,0 +1,15 @@
#!/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
suffix="${f##*.so}"
name="$(basename "$f" "$suffix")"
[ -h "$name" ] || ln -sf "$f" "$name"
[ -h "$name" ] || ln -sf "$f" "$name.1"
done && \
ldconfig
[ "$OLDPWD" ] && cd -
exec "$@"

View File

@ -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