3

I have a Docker application that will be able to read images off of any USB via a NodeJS + React application.

I have this working natively on my Linux box using udev rules, systemd, and a bash script:

# Call when a device is inserted
KERNEL=="sd[a-z]*", \
ACTION=="add", \
RUN+="/usr/bin/systemctl --no-block restart automount@%k.service"

# Call when a device is removed
KERNEL=="sd[a-z]*", \
ACTION=="remove", \
RUN+="/usr/bin/systemctl --no-block restart automount@%k.service"
[Service]
Type=forking
GuessMainPID=no
ExecStart=/usr/bin/bash /some/dir/scripts/example.sh %I

The bash script will take the dev path (i.e., /dev/sdc1) and use pmount to mount the device under /media/usb-mount: /usr/bin/pmount -u 000 -t "$TYPE" "$DEV_PATH" usb-mount.

When plugging in a USB device, it correctly mounts under /media/usb-mount. However, I cannot figure out how to pass this directory through to a docker container. I have added the following rules to my docker run command:

--device-cgroup-rule="c 8:* rmw" \
-v /media/:/host_media/ \

The first rule comes from here and the second rule mounts the /media host directory to the /host_media container directory.

This partially works. I am able to plug in and disconnect USB devices from my system, and I see the directories being created inside the container. However, the files on the USB drive are missing.

How can I see everything on the drive as well? Or is there a better way to do this?

Some Guy
  • 351
  • 1
  • 4
  • 20

0 Answers0