Skip to content

Instantly share code, notes, and snippets.

@danhigham
Created March 18, 2016 23:44
Show Gist options
  • Select an option

  • Save danhigham/67939ced008b96e7aa43 to your computer and use it in GitHub Desktop.

Select an option

Save danhigham/67939ced008b96e7aa43 to your computer and use it in GitHub Desktop.
Function to allow access to host devices from a container
function permit_device_control() {
local devices_mount_info=$(cat /proc/self/cgroup | grep devices)
local devices_subsytems=$(echo $devices_mount_info | cut -d: -f2)
local devices_subdir=$(echo $devices_mount_info | cut -d: -f3)
if [ ! -e /tmp/devices-cgroup ]; then
mkdir /tmp/devices-cgroup
mount -t cgroup -o $devices_subsytems none /tmp/devices-cgroup
fi
echo a > /tmp/devices-cgroup${devices_subdir}/devices.allow || true
umount /tmp/devices-cgroup || true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment