Use docker run -idt -v /dev:/dev --privileged --name delete ubuntu:18.04 /bin/bash
to new a container, and in container use apt-get install -y udev
to install udev.
When start udev, it reports next:
root@0947408dab9b:~# service udev start
* udev does not support containers, not started
Then, I change the init script in /etc/init.d/udev
, comments next 2 parts:
1) Comments next:
#if ! ps --no-headers --format args ax | egrep -q '^\['; then
# log_warning_msg "udev does not support containers, not started"
# exit 0
#fi
2) Comments next:
#if [ ! -w /sys ]; then
# log_warning_msg "udev does not support containers, not started"
# exit 0
#fi
Then, re-execute service udev start
:
root@0947408dab9b:/etc/init.d# service udev start
* Starting the hotplug events dispatcher systemd-udevd starting version 237
[ OK ]
* Synthesizing the initial hotplug events... [ OK ]
* Waiting for /dev to be fully populated... [ OK ]
Then, I verify the udev in container with some udev rules added, and unplug/plug some usb device, I saw it works.
So, my question is: why in udev init script disable this in container, it's really works... Possible any special scenario I'm not aware?
UPDATE:
Also add tests next:
1. I add a simple rule next:
root@0947408dab9b:/dev# cat /etc/udev/rules.d/100.rules
ACTION=="add", SYMLINK+="thisistestfile"
2. service udev restart
3. Unplug/Plug the usb mouse
We could see there is a file with the name "thisistestfile" in /dev
:
root@0947408dab9b:/dev# ls -alh /dev/thisistestfile
lrwxrwxrwx 1 root root 13 May 28 08:58 /dev/thisistestfile -> input/event12