7

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?

ichbinblau
  • 4,507
  • 5
  • 23
  • 36

2 Answers2

12

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.

grungegurunge
  • 841
  • 7
  • 13
1

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.
atline
  • 28,355
  • 16
  • 77
  • 113
  • I can't find section 2) in my host system's `/etc/init.d/udev`. Do I have to do anything inside the container except `service udev start`? – Raketenolli Nov 17 '20 at 10:47
  • The change is for `/etc/init.d/udev` in container, it's a separate udev system against hosts', so every operation should be operated in container. – atline Nov 18 '20 at 01:55