问题描述
使用 docker run -idt -v / dev:/ dev --privileged --name delete ubuntu:18.04 / bin / bash
新建一个容器,并在容器中使用 apt-get install -y udev
安装udev。
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.
启动udev时,会报告下一个:
When start udev, it reports next:
root@0947408dab9b:~# service udev start
* udev does not support containers, not started
然后,我在 /etc/init.d/udev $ c $中更改初始化脚本c>,评论下2个部分:
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
然后,重新执行服务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 ]
然后,我验证容器中的udev是否添加了一些udev规则,并拔出/插入了一些USB设备,我看到了它的工作。
Then, I verify the udev in container with some udev rules added, and unplug/plug some usb device, I saw it works.
所以,我的问题是:为什么在udev初始化脚本中在容器中禁用此功能,它确实有效...可能是我不知道的任何特殊情况?
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?
更新:
接下来还要添加测试:
1。接下来我添加一个简单的规则:
root@0947408dab9b:/dev# cat /etc/udev/rules.d/100.rules
ACTION=="add", SYMLINK+="thisistestfile"
2。服务udev重新启动
3。拔下/插入USB鼠标
我们可以看到 / dev $中有一个名为 thisistestfile的文件c $ c>:
root@0947408dab9b:/dev# ls -alh /dev/thisistestfile
lrwxrwxrwx 1 root root 13 May 28 08:58 /dev/thisistestfile -> input/event12
推荐答案
为什么 udev
在容器中禁用,确实有效
是通用设备管理器,在Linux系统上作为守护程序运行,并且在初始化新设备或删除设备时(通过网络链接套接字)侦听内核发出的事件从系统。 udev
现在是 systemd
。
Why udev
disabled in containers, it's really works
udev is a generic device manager running as a daemon on a Linux system and listening (via a netlink socket) to uevents the kernel sends out if a new device is initialized or a device is removed from the system. udev
is now part of systemd
.
我认为这与 udev $无关。 c $ c>,但在
docker
和 systemd
开发人员之间引起争议。 撰写了有关该主题的系列文章。我强烈建议和。
If you want to learn more about the conflict here is another good article.
这篇关于为什么udev初始化脚本默认禁用容器支持,而实际上却起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!