How to get host's udev events from a Docker container?

拈花ヽ惹草 提交于 2020-12-10 08:47:19

问题


In a Docker container, I am looking for a way to get the udev events on the host.
Using udevadm monitor, it sends back host's kernel events only in a container.

The question is whether there is a way to detect host's udev events or forward host's event to containers?


回答1:


This is how I made my container receive host events by udev:

docker run --net=host -v /run/udev/control:/run/udev/control

--net=host allows container and host operate through PF_NETLINK sockets, which are used by udev monitor to receive kernel events (found here)

/run/udev/control is a file, which udev monitor uses to check if udevd is already running. If it doesn't exist, monitoring is disabled.




回答2:


Just like above answer pointed out: we could enable --net=host, but host network is not suggested because of multiple known reasons.

In fact this issue happens just because it need NETLINK to communicate between kernel & user space, but if not use host network, host & container will in different netns, so enable udev in container could make them in same netns which then no need to use host network.

When we ran into this issue, we did next:

# apt-get install udev

# vim /etc/init.d/udev to comment some special settings:

    1) Comments next:
    #if [ ! -e "/run/udev/" ]; then
    #    warn_if_interactive
    #fi

    2) 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

# root@e751e437a8ba:~# service udev start
  [ ok ] Starting hotplug events dispatcher: systemd-udevd.
  [ ok ] Synthesizing the initial hotplug events (subsystems)...done.
  [ ok ] Synthesizing the initial hotplug events (devices)...done.
  [ ok ] Waiting for /dev to be fully populated...done.


来源:https://stackoverflow.com/questions/49687378/how-to-get-hosts-udev-events-from-a-docker-container

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!