What is the best way to expose a USB device (/dev/cu.usbserial
) to a running Docker container? Is it possible to alias the device to a different name within the container similar to how port mapping works? I am trying to read and write to the serial device (flash firmware) from the container since I have all the tools within the container. I have outlined everything that I have tried so far below.
--device
Using the --device
option, I receive the error: docker: Error response from daemon: error gathering device information while adding custom device "/dev/cu.usbserial": no such file or directory
.
--mount
& --volume
After adding the /dev
path to File Sharing under preferences, I tried the following command:
docker run -it --rm --volume $(pwd):/home/app/ --volume /dev/cu.usbserial:/dev/cu.usbserial --entrypoint "/bin/bash" container:tag
But this command actually just hangs forever. And using the --mount
analog below:
docker run -it --rm --volume $(pwd):/home/app/ --mount type=bind,source=/dev/cu.usbserial,target=/dev/cu.usbserial --entrypoint "/bin/bash" container:tag
I receive the following error: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /dev/cu.usbserial
.
I also tried to symlink the device to the directory that I attach to the container, but the container is not able to follow the link.
As @Peaceful James points out, if your host machine runs OSX, there is no current solution to this problem. The issue is being tracked here.
Try running your docker container in privileged mode:
sudo docker run -it --rm --volume $(pwd):/home/app/ --privileged --entrypoint "/bin/bash" container:tag
See here for details: https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities
NB: this won't work on "Docker for Mac". See here: https://github.com/docker/for-mac/issues/900
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With