Issues with USB Peripherals in Docker

Sometimes, it is a real pain to access devices such as USB modems inside the docker container. There are so many reasons causing the issue. Let’s discuss few of them in this article.

Issue# 1:

ERROR[4232]: chan_dongle.c:137 lock_create: open('/var/lock/LCK..ttyUSB2') failed: Permission denied

This issue is related to the permission as root user is only allowed to access the serial ports. To resolve the issue, perform the following steps;

  • First of all, add container to dialout and lock group with privileged access.
  • Mount USB ports as devices.
  • Mount the lock and dev as volumes.
  • To acheive above mentioned tasks, add the following to docker-compose.ymlfile.
  - dialout
  - lock
  - /dev/ttyUSB0:/dev/ttyUSB1
  - /dev/ttyUSB0:/dev/ttyUSB2
privileged: true
- /var/lock:/var/lock
- /dev:/dev

Issue# 2:

WARNING[4232]: chan_dongle.c:222 opentty: unable to open /dev/ttyUSB2: Device or resource busy

In Ubuntu, modem manager captures usb serial devices hence causing a device to be busy. It must be disabled so that our docker container can access it. We need Vendor and Product ID for this purpose.

  • Enlist the attached USB device by lsusb.
$ lsusb
Bus 001 Device 003: ID 05ac:8511 Apple, Inc. 
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 032: ID 0ca6:a050 Castles Technology Co., Ltd 
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  • In the output above 0ca6 is Vendor ID and a050  is Product ID. Note it down and we shall use it later on.
  • Create a new udev rule sudo nano /etc/udev/rules.d/99-ttyusb.rules to disable USB device access by modem manager with following code.
ATTRS{idVendor}=="0ca6" ATTRS{idProduct}=="a050", ENV{ID_MM_DEVICE_IGNORE}="1"
  • Change Vendor and Product ID according to your device and save the file by pressing Ctrl + X followed by Enter key.
  • Reload your udev rules now sudo udevadm control --reload-rules.
  • Reboot the machine sudo reboot.
5 3 votes
Article Rating
Notify of

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
1 year ago

you saved my time. thanks

Would love your thoughts, please comment.x