[SOLVED] Pass USB from proxmox to lxc to docker (Octoprint)

Zoker

Member
Oct 31, 2020
34
10
13
Hi there,

I want to run Octoprint on my proxmox server. For that I created a LXC container based on alpine OS and installed docker in it (that's what I do for all my other containers as well). I then created a USB passtrough to the lxc container by creating a /etc/udev/rules.d/99-usb-serial.rules file with this content:

Code:
SUBSYSTEM=="tty", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740" SYMLINK+="tty3DPRINTER"
KERNEL=="ttyUSB[0-9]*",MODE="0666"

I also added this to my LXC config:
YAML:
lxc.mount.entry: /dev/tty3DPRINTER dev/ttyUSB0 none bind,optional,create=file

Within the LXC container I created this compose file:
YAML:
version: '3.8'
services:
  octoprint:
    image: octoprint/octoprint
    container_name: Octoprint
    restart: always
    ports:
      - 80:80/tcp
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    volumes:
      - ~/files/octoprint:/octoprint

When I now start octoprint it can not connect to my 3D printer.

This is the output of ls -la /dev/tty* within the LXC container:
Code:
Octoprint:~# ls -ls /dev/tty*
     0 crw-rw-rw-    1 nobody   nobody      5,   0 Jan  8 12:01 /dev/tty
     0 crw-------    1 root     root      136,   1 Jan  8 12:45 /dev/tty1
     0 crw--w----    1 root     root      136,   2 Jan  8 12:31 /dev/tty2
     0 crw-rw----    1 nobody   nobody    166,   0 Jan  8 12:01 /dev/ttyUSB0

And this the output of the same command in the docker container:
Code:
root@05e466ae2506:/octoprint# ls -la /dev/tty*
crw-rw-rw- 1 nobody nogroup   5, 0 Jan  8 12:01 /dev/tty
crw------- 1 root   root    136, 1 Jan  8 12:44 /dev/tty1
crw--w---- 1 root   root    136, 2 Jan  8 12:31 /dev/tty2
crw-rw---- 1 nobody nogroup 166, 0 Jan  8 12:01 /dev/ttyUSB0

I'm not sure how to solve this. But I think it is maybe a permission issue somewhere between the LXC container and the docker container.

Would be amazing, if someone can give me a hint how to solve this. Thanks!
 
This is the output of ls -la /dev/tty* within the LXC container:
Code:
Octoprint:~# ls -ls /dev/tty*
     0 crw-rw-rw-    1 nobody   nobody      5,   0 Jan  8 12:01 /dev/tty
     0 crw-------    1 root     root      136,   1 Jan  8 12:45 /dev/tty1
     0 crw--w----    1 root     root      136,   2 Jan  8 12:31 /dev/tty2
     0 crw-rw----    1 nobody   nobody    166,   0 Jan  8 12:01 /dev/ttyUSB0
...
Would be amazing, if someone can give me a hint how to solve this. Thanks!

A hint: only "nobody" can access the ttyUSB0 device. From what (little) I understand about lxc's, you have 3 choices:

1. Tell udev on the host machine to give more permissions to the file (0666 so that it's accessible to 'other')
2. Make the lxc privileged (and then fiddle with perms on the lxc side)
3. Mess around with mapping permissions/users in the lxc.conf (which I never understood.)

Personally, I'm lazy and usually do #1. ;)
 
Maybe try dev0: /dev/tty3DPRINTER,gid=0,uid=0 instead? I don't know how to do a rename with the new container dev-passthrough.
When I do that, I can't seem to mount the device inside the docker container:
Code:
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error creating device nodes: mount /dev/ttyUSB0:/var/lib/docker/overlay2/31968128fc8c8bf1996792df6640002bd6515a49221be4ac4f106ea3bc283915/merged/dev/ttyUSB0 (via /proc/self/fd/6), flags: 0x1000: no such file or directory: unknown

1. Tell udev on the host machine to give more permissions to the file (0666 so that it's accessible to 'other')
But isn't that what

Code:
KERNEL=="ttyUSB[0-9]*",MODE="0666"

does?
 
But isn't that what

Code:
KERNEL=="ttyUSB[0-9]*",MODE="0666"

does?
Perhaps that is the intent, but if so, it doesn't seem to be working. It's setting perms to 0660:

Code:
0 crw-rw----    1 nobody   nobody    166,   0 Jan  8 12:01 /dev/ttyUSB0

I'm unable to access my proxmox machine right now, so I can get the proper udev line, but I'm sure someone will be able to jump in. In the meantime, you can try to manually "fix" it on the host (proxmox) machine with "chmod 666 /dev/ttyWhatever" (edit as needed), verify the the perms are changed on both the proxmox host _and_ within the lxc, and then check if things work.
 
I'm unable to access my proxmox machine right now, so I can get the proper udev line, but I'm sure someone will be able to jump in. In the meantime, you can try to manually "fix" it on the host (proxmox) machine with "chmod 666 /dev/ttyWhatever" (edit as needed), verify the the perms are changed on both the proxmox host _and_ within the lxc, and then check if things work.

Thanks that worked
The issue seems to be, that the USB is mounted to /dev/ttyACM0 instead of /dev/ttyUSB0 and therefore the permissions rule does not apply here.

Again thank you very much!
 
  • Like
Reactions: garyd9

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!