moby icon indicating copy to clipboard operation
moby copied to clipboard

Docker not handling serial path in ARM/RPI hosts

Open fsamir opened this issue 8 years ago • 21 comments

Description Docker container is not properly handling serial port paths, when serial devices are connected/disconnected in ARM Linux(tested on RPI 2 and 3).

Problems:

  • USB device under /dev/ttyUSB0 have to be connected before docker starts, otherwise they wont exist.
  • Unplugging a device that was detect and properly mapped, does't un-map the device, hence most serial-port libraries cannot determine it was disconnected and crashes.

Steps to reproduce the issue:

  1. Boot the docker container with privileged and /dev/ttyUSB0 device mapped
  2. Plug the USB cable.
  3. Unplug the USB cable.

Describe the results you received:

  1. Unless the USB is plugged prior to docker booting, the path /dev/ttyUSB0 is not mounted.
  2. lsusb (in the container), finds the devices with no problems at all, regardless if they were connected before or after booting.
  3. dmesg also detects the devices connects and disconnects as above.
  4. The problems seems to be just related to mapping the path to /dev/ttyUSB(0|1|2|3)
  5. The mapping works on the host, as expected.

Describe the results you expected:

  1. serial paths /dev/ttyUSBX to be mounted even if the USB cable was plugged after docker has booted.
  2. /dev/ttyUSBX to be unmounted/removed when I unplug the USB cable.

Additional information you deem important (e.g. issue happens only occasionally): Relevant part of my docker-compose(Noticed I am mapping the devices and also running as priviliged). I also tried a number of combinations, adding and removing the devices and /dev/bus/usb volume, without any success.

devices:
- "/dev/mem:/dev/mem"
- /dev/bus/usb:/dev/bus/usb:rwm
- /dev/ttyUSB0:/dev/ttyUSB0:rwm
- /dev/ttyUSB1:/dev/ttyUSB1:rwm
privileged: true
tty: true
volumes:
- /dev/bus/usb:/dev/bus/usb

Output of docker version:

$ docker-compose -v
docker-compose version 1.8.0, build 94f7016

$ docker -v
Docker version 1.11.1, build 5604cbe

$ uname -a
Linux dev-reefmate 4.4.11-v7+ #888 SMP Mon May 23 20:10:33 BST 2016 armv7l GNU/Linux

Additional environment details (AWS, VirtualBox, physical, etc.): My environment:

  • Docker 1.11 running on a RPI 3/raspibian lite
  • Docker image base on resin/raspberrypi3-node:4.3
  • USB Serial device: Arduino nano, but it happens with any USB peripheral.

fsamir avatar Oct 27 '16 00:10 fsamir

You can use docker run -v /dev:/dev ... I think to work around dynamic devices, that should behave as the host does I believe.

justincormack avatar Oct 27 '16 09:10 justincormack

@justincormack unfortunately that also doesn't work. Thanks

fsamir avatar Oct 27 '16 12:10 fsamir

@fsamir in what way doesn't it work? you still need --privileged but not to use --device I think, but I don't see why it shouldn't work.

justincormack avatar Oct 27 '16 14:10 justincormack

Justin, It doesn't work as in, the symptoms are the same described in the first post.

I tried multiple combinations of configs, always keeping 'privileged' and with and without '/dev' in '-- devices'.

I am suspicious it is something with de image I am using and not with docker... On Fri., 28 Oct. 2016 at 1:23 am, Justin Cormack [email protected] wrote:

@fsamir https://github.com/fsamir in what way doesn't it work? you still need --privileged but not to use --device I think, but I don't see why it shouldn't work.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/docker/docker/issues/27807#issuecomment-256655460, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJcx_ycuXNMjOm6XNRLqEAnMgmz4ju_ks5q4LPUgaJpZM4KhzmP .

fsamir avatar Oct 27 '16 21:10 fsamir

I'm having the same issue. The only work around is to restart docker after the usb is connected?

h3rj4n avatar Oct 28 '16 18:10 h3rj4n

As far as I can tell, yes. Also, in case the cable is disconnected, make sure the piece of code listing the available serial ports, can handle the now invalid serial path.

This pretty much makes docker unusable with most iot projects, since they connect to micro controllers via serial port. On Sat., 29 Oct. 2016 at 5:47 am, h3rj4n [email protected] wrote:

I'm having the same issue. The only work around is to restart docker after the usb is connected?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/docker/docker/issues/27807#issuecomment-256998165, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJcx5S0HuOmaC3OjuaLEoUWZ_qtQJpIks5q4kNJgaJpZM4KhzmP .

fsamir avatar Oct 28 '16 20:10 fsamir

FYI, the problem is also reproducible on hypriot OS for raspberry pi, as the host. My previous report was on Raspibian lite. Linux black-pearl 4.4.15-hypriotos-v7+ #1 SMP PREEMPT Mon Jul 25 08:46:52 UTC 2016 armv7l GNU/Linux

fsamir avatar Nov 02 '16 06:11 fsamir

As far as I can see using docker run -v /dev:/dev ... is exactly the same as running on the host as far as getting all the device nodes being created and removed, it seems to work as expected (from working on another issue), so I think it is an issue with the code. USB serial devices are kind of horrible from my experience, I always tried to leave them plugged in at all times.

justincormack avatar Nov 03 '16 10:11 justincormack

Justin, Thanks for your time. It has nothing to do with the code. When I remove the USB cable, and run 'ls /dev/' in the container, the path '/dev/ttyUSB0' is still there.

It may have something to do with it being docker on a rpi and I am will try it on a Mac to check if the behaviour is different. Thanks On Thu., 3 Nov. 2016 at 9:43 pm, Justin Cormack [email protected] wrote:

As far as I can see using docker run -v /dev:/dev ... is exactly the same as running on the host as far as getting all the device nodes being created and removed, it seems to work as expected (from working on another issue), so I think it is an issue with the code. USB serial devices are kind of horrible from my experience, I always tried to leave them plugged in at all times.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/docker/docker/issues/27807#issuecomment-258110201, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJcx2cFptClvMkBMc1t2UroYAnP2Mp_ks5q6brUgaJpZM4KhzmP .

fsamir avatar Nov 03 '16 20:11 fsamir

@fsamir have you been able to test on a different environment?

thaJeztah avatar Dec 06 '16 12:12 thaJeztah

@thaJeztah I have tried with a MacOS as a host, but I couldn't get the USB ports to be exposed to the container, at all. This issue is tracked here: https://forums.docker.com/t/how-to-share-an-non-storage-usb-device-between-host-and-container-on-osx/9385/2

Also, I don't have a physical Linux machine(other than PIs) that I can plug USB peripherals, that is why I haven't answered before.

fsamir avatar Dec 07 '16 01:12 fsamir

I can confirm that I'm also having this problem. I have an SD card connected at /dev/disk1, and when I attempt to bind it using docker run -it --privileged -v /dev/disk1:/dev/disk1 ubuntu I get the following error:

The path /dev/disk1
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.
..

When I use docker run -it --device=/dev/disk1 ubuntu I get the following error:

docker: Error response from daemon: linux runtime spec devices: error gathering device information while adding custom device "/dev/disk1": lstat /dev/disk1: no such file or directory.

Is this behaviour expected? There definitely is a device connected as the output of diskutil shows it.

sam3d avatar Jan 19 '17 19:01 sam3d

@sam3d yes, that's expected, because on OS X, the docker daemon runs in a VM, which does not have access to devices on the OS X host (see the error message)

thaJeztah avatar Jan 23 '17 13:01 thaJeztah

Ah yes of course I totally overlooked that, I'm so used to Docker in linux I keep forgetting how it works on OS X! So is there no way currently to grant the container access to devices on the OS X host?

sam3d avatar Jan 23 '17 14:01 sam3d

No, not at present. In theory we can do things like PCI pass through, or other remote access options, but the underlying support in hyperkit is not there yet.

On 23 Jan 2017 2:17 p.m., "Sam Holmes" [email protected] wrote:

Ah yes of course I totally overlooked that, I'm so used to Docker in linux I keep forgetting how it works on OS X! So is there no way currently to grant the container access to devices on the OS X host?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/docker/docker/issues/27807#issuecomment-274498855, or mute the thread https://github.com/notifications/unsubscribe-auth/AAdcPDHeK-MF2yPz7B0I_jqFMq7GXXFSks5rVLaNgaJpZM4KhzmP .

justincormack avatar Jan 23 '17 14:01 justincormack

@justincormack I finally got my hands on a Linux/Ubuntu laptop as Docker host and I can confirm it works fine. Hence, the issue is reproducible only on RPI (potentially all ARM) hosts.

Test details:

docker run -it --privileged -v /dev:/dev ubuntu
ubuntu@ubuntu:~$ docker info
Containers: 3
 Running: 0
 Paused: 0
 Stopped: 3
Images: 1
Server Version: 1.12.1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 11
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: host overlay bridge null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor
Kernel Version: 4.4.0-59-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.69 GiB
Name: aleasha
ID: KGGC:C7TE:4MGD:NIHK:3NTT:5XGX:NABV:GFPK:CDOJ:YUY3:A2DX:6GJZ
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
 127.0.0.0/8
uname -a
Linux aleasha 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
```

fsamir avatar Jan 24 '17 01:01 fsamir

This is an interesting thread. I do a fair amount with the Raspberry Pi and IoT. I only generally use serial for interfacing with Arduinos - most of the other time it's GPIO or i2c.

@fsamir Can you give me a quick outline of what you're doing (is it Arduino communication)? Maybe I can reproduce it at my end with a Pi and Raspbian.

@justincormack - does --device still need --privileged for reading from a serial device?

alexellis avatar Feb 18 '17 18:02 alexellis

I have similar problem, but in my case I need to list /dev/serial/by-id. I'm executing tests using Image base, Alpine 3.4, CentOS 7 and Ubuntu 16.04, but not any this Images lists serial devices.

My Java Application translate the Id Serial to port name connected.

# ls -al /dev/serial/by-id
total 0
drwxr-xr-x 2 root root 60 Nov 10 09:43 .
drwxr-xr-x 4 root root 80 Nov 10 09:43 ..
lrwxrwxrwx 1 root root 13 Nov 10 09:43 usb-metrologico_FT232R_USB_UART_AH038RBA-if00-port0 -> ../../ttyUSB0

Command to run my Test Containers:

# docker run --privileged --device=/dev/serial/by-id:/dev/serial/by-id:rwm -it java:8 bash
sudo docker run --privileged --device=/dev/serial/by-id:/dev/serial/by-id:rwm -it mamohr/centos-java:jdk8 bash

Out put:

[root@a3619e9e3d0b /]# ls /dev/s
sda       sda1      sda2      sda3      sg0       shm/      snapshot  snd/      stderr    stdin     stdout

Docker info:

Containers: 13
 Running: 5
 Paused: 0
 Stopped: 8
Images: 20
Server Version: 17.09.0-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 87
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.10.0-37-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.693GiB
Name: FTSSJCD03
ID: REBM:EUO7:CK54:MOY3:SD6T:SY7C:7IXI:TDOD:TX54:2YX2:B4SC:ELDR
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false

thiagolsfortunato avatar Nov 10 '17 12:11 thiagolsfortunato

Same issue here...

Would it be possible that the "/dev/... no such file of directory" was a warning rather than an error.

Sorry if this is not feasible, but I would expect Docker to take note I want the device to be exposed inside... whenever it becames available, not on startup. This behavior could solve the problem for pluggable devices.

Thanks!

cconde avatar May 08 '20 06:05 cconde

This is STILL a problem two YEARS later!

I'm trying to use Arduino-cli with devices that are constantly unplugged. When they are, the tty device disappears and my Arduino-CLI container (running under Debian) crashes. Why?

bwims avatar Jul 24 '22 11:07 bwims

I take it back!

The solution is not to add a device but to bind the /dev folder as here: https://github.com/moby/moby/issues/34290#issuecomment-319421818

Phew!

bwims avatar Jul 24 '22 12:07 bwims

I don't see any recent activity on this issue, and there seems to be a solution now.

sam-thibault avatar Dec 13 '22 13:12 sam-thibault

Can someone let me know what is the solution? I am still facing the issue

pavanupb avatar Dec 15 '23 13:12 pavanupb