Cannot map USB device to docker container

I cannot map my usb device with the home assistant container.

$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 nov 27 09:28 /dev/ttyUSB0
$ groups
adm dialout sudo audio kvm lpadmin docker

I mapped ttyUSB0 device in my docker compose file:

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    restart: unless-stopped
    volumes:
      - ./homeassistant/config:/config
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    network_mode: host

And this is the error when I run the container:

$ docker compose up
Error response from daemon: error gathering device information while adding custom device "/dev/ttyUSB0": no such file or directory

If I add the priviliged property to the compose file I can run the container but I get this error when serial port is used (I’d rather not enable privileged mode…):

    priviliged: true
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0

And this is the error:

homeassistant  |   File "/usr/local/lib/python3.10/site-packages/serial/__init__.py", line 90, in serial_for_url
homeassistant  |     instance.open()
homeassistant  |   File "/usr/local/lib/python3.10/site-packages/serial/serialposix.py", line 325, in open
homeassistant  |     raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
homeassistant  | serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/ttyUSB0'

If I run docker compose up with sudo all works correctly, so I think it’s just a permissions issue.

I can’t figure out how to correctly map the USB device to the container.

Did you manage to solve this issue? i’m encountering the same issue… ;(