Open aldas opened 1 year ago
When that device "/dev/ttyUSB0" is unplugged the container will be removed
Do you have any daemon logs from when that happens? I'm mostly curious about the part where you mention that the container is removed (I'd expect the container to still be there, but possibly as "failing to start")
I am probably using wrong terminology here. by "removed" I mean it does not show up in "docker ps" list as it fails to start at all (does not get even state where entry-point is executed)
This is example with some logs
Insert USB device to my PC. This is cheap USB to UART device /dev/ttyUSB0
[55270.336258] usb 1-14: new full-speed USB device number 6 using xhci_hcd
[55270.519244] usb 1-14: New USB device found, idVendor=10c4, idProduct=ea60, bcdDevice= 1.00
[55270.519260] usb 1-14: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[55270.519268] usb 1-14: Product: CP2102 USB to UART Bridge Controller
[55270.519275] usb 1-14: Manufacturer: Silicon Labs
[55270.519281] usb 1-14: SerialNumber: 0001
[55270.566086] usbcore: registered new interface driver usbserial_generic
[55270.566127] usbserial: USB Serial support registered for generic
[55270.571010] usbcore: registered new interface driver cp210x
[55270.571053] usbserial: USB Serial support registered for cp210x
[55270.571149] cp210x 1-14:1.0: cp210x converter detected
[55270.573515] usb 1-14: cp210x converter now attached to ttyUSB0
Create docker compose file with USB device mapped to that container. In this small example to simulate restarting the container I use ping to run 10seconds and then exit thus forcing container to restart
version: "3.7"
services:
usb_reader:
image: alpine:latest
command: ['ping', '-c', '10', 'google.com']
restart: always
devices:
- /dev/ttyUSB0:/dev/ttyUSB0:rw
device_cgroup_rules:
# https://stackoverflow.com/a/62758958/2514290
- "c 188:* rmw"
- "c 166:* rmw"
- "c 4:* rmw"
group_add:
- dialout
volumes:
- /run/udev:/run/udev:ro
start container sudo docker-compose up -d
check with sudo docker stats
that container runs, exits and gets restarted.
Unplug USB device from PC
Container is removed from list and does not seems to be "restarted"
journald has these lines as last lines
okt 19 22:55:35 aldas 8331c0336ed3[1947]: PING google.com (216.58.209.206): 56 data bytes
okt 19 22:55:35 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=0 ttl=56 time=4.782 ms
okt 19 22:55:36 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=1 ttl=56 time=4.599 ms
okt 19 22:55:37 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=2 ttl=56 time=4.466 ms
okt 19 22:55:38 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=3 ttl=56 time=4.705 ms
okt 19 22:55:39 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=4 ttl=56 time=4.515 ms
okt 19 22:55:40 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=5 ttl=56 time=4.181 ms
okt 19 22:55:41 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=6 ttl=56 time=4.732 ms
okt 19 22:55:42 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=7 ttl=56 time=4.386 ms
okt 19 22:55:43 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=8 ttl=56 time=4.804 ms
okt 19 22:55:44 aldas 8331c0336ed3[1947]: 64 bytes from 216.58.209.206: seq=9 ttl=56 time=4.593 ms
okt 19 22:55:44 aldas 8331c0336ed3[1947]:
okt 19 22:55:44 aldas 8331c0336ed3[1947]: --- google.com ping statistics ---
okt 19 22:55:44 aldas 8331c0336ed3[1947]: 10 packets transmitted, 10 packets received, 0% packet loss
okt 19 22:55:44 aldas 8331c0336ed3[1947]: round-trip min/avg/max = 4.181/4.576/4.804 ms
okt 19 22:55:45 aldas dockerd[1947]: time="2023-10-19T22:55:45.001507083+03:00" level=info msg="ignoring event" container=8331c0336ed3ddc8c0d048cf14c81dc619534c74bc59ec6c02bfd1a8a9a79050 module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
okt 19 22:56:45 aldas dockerd[1947]: time="2023-10-19T22:56:45.076426861+03:00" level=error msg="8331c0336ed3ddc8c0d048cf14c81dc619534c74bc59ec6c02bfd1a8a9a79050 cleanup: failed to delete container from containerd: container \"8331c0336ed3ddc8c0d048cf14c81dc619534c74bc59ec6c02bfd1a8a9a79050\" in namespace \"moby\": not found"
okt 19 22:56:45 aldas dockerd[1947]: time="2023-10-19T22:56:45.196103564+03:00" level=error msg="restartmanger wait error: error gathering device information while adding custom device \"/dev/ttyUSB0\": no such file or directory"
okt 19 22:56:45 aldas dockerd[1947]: time="2023-10-19T22:56:45.196103564+03:00" level=error msg="restartmanger wait error: error gathering device information while adding custom device \"/dev/ttyUSB0\": no such file or directory"
Maybe there is a built in workaround for this situation. It seems little bit silly to build "watchdog" process or CRON job to check for this situation and then trigger that container to be run again. It would be nice if engine could keep trying to recover from this situation by trying to start that container - until that device reappears
I found this https://github.com/moby/moby/issues/35359 but suggestions like mounting whole /dev/bus/usb
are no particularly safe as I would like to expose this device and not other things to that container.
@thaJeztah is current behavior working as intended?
Description
I was directed here by https://github.com/docker/compose/issues/11075
I have a docker compose file that runs service that read USB serial device (cheap usb to serial GPS on a sailing boat). When that device "/dev/ttyUSB0" is unplugged the container will be removed and will no recover when that USB replugged and
/dev/ttyUSB0
reappears.It would be essential that this container will not be removed from running list and stays in restart loop - thus enabling recovery/0-maintenance after reboots/disconnects
compose file is this:
Reproduce
Expected behavior
No response
docker version
docker info
Additional Info
No response