0

I'm trying to get hotplug working under Docker inside nodejs.

My nodejs test app:

// @ts-ignore
import usb from 'usb';

(async () => {
    usb.on('attach', (device: any) => console.log("attache"));
    usb.on('detach', (device: any) => console.log("detach"));
})();

My testbad container:

sudo docker run --rm -it --entrypoint bash -v /dev:/dev -v /var/run/udev:/var/run/udev -v $(pwd)/workdir:/app --privileged ubuntu:latest

There is some more packages required to get everything working (for now its bash script, end game is to have Dockerfile)

#!/bin/bash
apt update && apt-get install -y ca-certificates curl curl build-essential libgphoto2-dev libcups2-dev udev libudev-dev
curl -sL https://deb.nodesource.com/setup_13.x | bash -
apt -y install nodejs
npm i -g ts-node typescript

To get everything setup temporarily.

As it stands if i run udevadm monitor a get events etc. But if I run my test script no events are recevied.

Also if i run my test app outside docker everything works as expected.

Have anybody tried this before?

Thanks

Kekec
  • 1
  • 2
  • 1
    I can make it work if network is set to host: `sudo docker run --rm -it --entrypoint bash -v /dev:/dev -v /var/run/udev:/var/run/udev -v $(pwd)/workdir:/app --privileged --net=host ubuntu:latest` There is also a solution using ionotify: https://www.guidodiepen.nl/2016/05/notification-of-new-usb-devices-in-docker-container/ – Kekec Jul 07 '20 at 07:52
  • Also https://stackoverflow.com/questions/49687378/how-to-get-hosts-udev-events-from-a-docker-container – Kekec Jul 07 '20 at 07:56

0 Answers0