mirror of
				https://github.com/keylase/nvidia-patch.git
				synced 2025-11-04 06:32:02 +00:00 
			
		
		
		
	
							
								
								
									
										10
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Dockerfile
									
									
									
									
									
										Normal 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"]
 | 
			
		||||
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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**: 
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										15
									
								
								docker-entrypoint.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								docker-entrypoint.sh
									
									
									
									
									
										Normal 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 "$@"
 | 
			
		||||
							
								
								
									
										6
									
								
								patch.sh
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user