运行可访问设备的容器,而无需以 root 身份运行

运行可访问设备的容器,而无需以 root 身份运行

我想运行一个zigbee2mqtt容器。

我需要将设备绑定到容器,执行以下操作:

devices:
  - "/dev/serial/by-id/usb-Texas_Instruments_\
TI_CC2531_USB_CDC___0X00124B00194AD935-if00:/dev/ttyUSB0"

我想以另一个用户身份启动,例如:

user: "${DOCKER_UID}:${DOCKER_GID}"

但它因错误而挂起,我认为它具有正确的访问权限(当我不指定用户时不会出现错误)。有错误日志:

  zigbee2mqtt:info 10/27/2019, 5:18:17 PM Logging to directory: '/app/data/log/2019-10-27.17-18-17'
  zigbee2mqtt:info 10/27/2019, 5:18:18 PM Starting zigbee2mqtt version 1.6.0 (commit #e26ad2a)
  zigbee2mqtt:info 10/27/2019, 5:18:18 PM Starting zigbee-shepherd
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: Port is not open
    at SerialPort.close (/app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/stream.js:425:29)
    at Znp.<anonymous> (/app/node_modules/zigbee-herdsman/dist/znp/znp.js:107:37)
    at Generator.next (<anonymous>)
    at /app/node_modules/zigbee-herdsman/dist/znp/znp.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/app/node_modules/zigbee-herdsman/dist/znp/znp.js:3:12)
    at SerialPort.serialPort.open (/app/node_modules/zigbee-herdsman/dist/znp/znp.js:103:45)
    at SerialPort._error (/app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/stream.js:197:14)
    at binding.open.then.err (/app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/stream.js:241:12)
Emitted 'error' event at:
    at SerialPort.onerror (_stream_readable.js:690:12)
    at SerialPort.emit (events.js:182:13)
    at SerialPort._error (/app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/stream.js:199:10)
    at process.nextTick (/app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/stream.js:204:31)
    at process._tickCallback (internal/process/next_tick.js:61:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

解决这个问题的选项/最佳方法是什么?
我没有看到任何安全问题给予用户对此 CC2531(Zigbee 接收器)的完全权限

答案1

我不记得是否/如何在 docker 中进行用户映射。不过,我只想使用文件权限:zigbee_device向主机添加一个新组 ( ),在设备上设置权限,以便该组中的用户可以读取和写入。然后让容器将其作为其组之一运行。

相关内容