USB devices mapping not works with docker desktop

Hi, I noticed this behavior, if I start my container (docker compose up) without starting docker desktop, everything works fine and I can access USB devices.
If instead I start the container AFTER starting docker desktop, nothing works anymore.

I found out that when docker desktop is not running the docker context of my user is default.
Instead after starting docker desktop the context is desktop-linux.

If I try to run container when docker desktop is running I have this error:

foo@pop-os:~/HomeAssistant$ docker compose up
[+] Running 1/1
 ⠿ Container homeassistant  Created                                                                                                           0.2s
Attaching to homeassistant
Error response from daemon: error gathering device information while adding custom device "/dev/ttyUSB0": no such file or directory

So, does it depend on docker desktop or does it depend on context?
Is there any way to make this work with docker desktop?

This is because Docker Desktop runs everything in a virtual machine. You can mount files info the virtual machine not everything and /dev/ is a special folder for special files to handle hardwares. I am not sure if it is even possible to mount it into a virtual machine, but if it is, you should check the Docker Desktop settings:

Preferences » Resources » File sharing.

I am on macOS now, but I believe it should be there on Linux too. If /dev is not in the list, then it tries to mount the device from the virtual machine which does not have it.

About contexts:

Without starting Docker Desktop, you run Docker CE.

I recommend you to remove either Docker CE or Docker Desktop to avoid confusion. I know, Docker says that you can run Docker CE and Desktop totegther, but in practice, it can be a problem especially if you don’t have a deeper knowledge about the two different softwares.

Hi, I tried adding /dev to file sharing but it still gives the same error.

Then it is probably not possible. You can mount the USB device on the host and mount only the mounted folder into the container. If you really want to mount devices, use Docker CE without the Desktop. Docker Desktop has its limits.