Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing a tty serial device requires privileged and doesn't work #900

Open
reconbot opened this issue Nov 5, 2016 · 116 comments
Open

Exposing a tty serial device requires privileged and doesn't work #900

reconbot opened this issue Nov 5, 2016 · 116 comments

Comments

@reconbot
Copy link

reconbot commented Nov 5, 2016

Expected behavior

That I can expose a tty dev device from my mac to a linux container by running.

$ docker run --rm -it -v `pwd`:/app --device /dev/tty.usbmodem1421 node bash

Actual behavior

$ docker run --rm -it -v `pwd`:/app --device /dev/tty.usbmodem1421 node bash
docker: Error response from daemon: linux runtime spec devices: error gathering device information while adding custom device "/dev/tty.usbmodem1421": lstat /dev/tty.usbmodem1421: no such file or directory.

I can work past this with --privileged but I don't see it in /dev/

$ docker run --rm -it -v `pwd`:/app --device /dev/tty.usbmodem1421 --privileged node bash
root@5a6a7f6b8e58:/# ls /dev/tty.*
ls: cannot access /dev/tty.*: No such file or directory

According to the docs on docker run I shouldn't need --privileged.

Information

  • Full output of the diagnostics from "Diagnose & Feedback" in the menu
Docker for Mac: version: 1.12.3-beta29.3 (619507e)
OS X: version 10.12.1 (build: 16B2555)
logs: /tmp/E9C6B44E-7492-484A-A6EF-EE5BE163959F/20161105-153323.tar.gz
[OK]     vmnetd
[OK]     dns
[OK]     driver.amd64-linux
[OK]     virtualization VT-X
[OK]     app
[OK]     moby
[OK]     system
[OK]     moby-syslog
[OK]     db
[OK]     env
[OK]     virtualization kern.hv_support
[OK]     slirp
[OK]     osxfs
[OK]     moby-console
[OK]     logs
[OK]     docker-cli
[OK]     menubar
[OK]     disk

Steps to reproduce the behavior

  1. hook up a tty serial device such as an Arduino, usb serial dongle, modem, cash drawer, etc to your mac
  2. Run the commands above to expose it's /dev/tty.usbXXXX device to the docker image
  3. Look for the device
@justincormack
Copy link
Member

Unfortunately the Mac and Linux are running in different operating systems and cannot see the same devices. I think there are some existing issues, the way to implement it will differ for different device types, but it is not trivial.

@larsks
Copy link

larsks commented Nov 5, 2016

Take a look at boot2docker/boot2docker#707 for some discussion on this topic.

@reconbot
Copy link
Author

reconbot commented Nov 5, 2016

That all makes sense. Should we have some sort of error instead of a silent failure?

@ijc
Copy link
Contributor

ijc commented Nov 15, 2016

As @justincormack says this is (probably) possible but is likely to be non-trivial and is not currently a priority for us. I will file a wishlist ticket for this internally. Please 👍 the top comment if you are interested in this feature.

@SiKing
Copy link

SiKing commented Jan 16, 2017

@ijc25 Just curious: if I could convince my client to throw some money at this specifically, would that bump the priority?

@ijc
Copy link
Contributor

ijc commented Jan 19, 2017

@SiKing,

If someone (or someone's client's hired contractor) was to raise a PR against https://github.com/docker/hyperkit which added the necessary underlying support for USB device passthrough (i.e. causing the USB device to appear within the VM so the Linux usb tty class driver can be run on top) or adding some sort of serial/tty passthrough functionality (I'm not sure how that would look, but it might be a plausible approach) and work with the team to get that PR into an acceptable state to be merged into hyperkit then it ought then to be possible for d4m users to fudge things themselves to enable the passthrough locally, although it clearly wouldn't be a Supported d4m feature. Maybe d4m could supply a (most likely also unsupported) way to add hyperkit command line options to enable people to do this sort of thing more easily (at their own risk, get to keep both pieces if it breaks etc).

Another plausible alternative (and likely much simpler to achieve than passthrough if it works) might be to investigate libusb and/or usb over ip between your container and a daemon on the host, it's possible that might even be possible to setup without changes to either hyperkit or d4m (AIUI the wire protocol is intended to be portable, i.e. Mac talking to Linux is supposed to work, I don't know if that is really true though).

@gw0
Copy link

gw0 commented Jan 27, 2017

One direction to achieve a workaround is with USB over IP for which a few commercial solutions exist. Nevertheless, the Docker VM that is based on Alpine Linux does not include all necessary kernel modules (vhci-hcd). I prepared a privileged Docker container to build Alpine Linux kernel modules and insert them in the kernel of the Docker VM. Does anyone know of a free and possibly open-source USB over IP solution that works on Mac and could be used with that?

@WolfgangFahl
Copy link

WolfgangFahl commented Sep 1, 2017

As @justincormack says this is (probably) possible but is likely to be non-trivial and is not currently a priority for us.

together with #77 and the dreadful (know limitations) in https://docs.docker.com/docker-for-mac/networking/ these are the showstoppers for using Docker on OSX from my point of view and the comment "not currently a priority for us" is not what I would have expected.

For a viable business I would expect that necessary / mandatory things to make virtualization useful should be high on the priority list. If I can not access simple devices like my usb devices or disk from a container what use can I make of container based virtualization? I'll have to still use VMWare and what is worse if i like docker I will have to go thru all kinds of tricks to make VMWare my host environment and docker work together.

When I first learned about docker I found the idea of having the option to run containers based on the same Dockerfile in windows, linux and Mac OS environments great. In the meantime I am more than disapppointed. Currently I think there is a complete failure of Docker to deliver on this idea in real world projects that need access to disks, network, graphics and devices.

@gw0
Copy link

gw0 commented Sep 20, 2017

@WolfgangFahl Don't be so upset, the Docker Inc. has shown numerous times, that they do not care about the problems and use cases of small users. They even reject pretty well-designed pull requests that solve various issues.

@lmapii
Copy link

lmapii commented Mar 12, 2018

second this one. makes docker pretty much unusable for anything but web services ..

@carusso
Copy link

carusso commented Mar 23, 2018

Basic networking and device pass-throughs from the host to the guest system are table stakes for virtualization. I was excited to start using the OSX Docker but quickly realized that it's just not ready yet.

@docker-robott
Copy link
Collaborator

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale comment.
Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale

@alranel
Copy link

alranel commented Aug 15, 2018

/remove-lifecycle stale

@hantuzun
Copy link

I need to install Linux to my MacBook right now, just for this limitation. I'd be great if Docker Inc. would consider working on this issue.

@docker-robott
Copy link
Collaborator

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale comment.
Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale

@quincarter
Copy link

Any update on if this feature will get implemented in docker? USB Passthrough?

I also found this roadmap issue.

docker/roadmap#511

@Semmu
Copy link

Semmu commented Dec 3, 2023

just a PSA, there are other alternatives for running containers on a Mac, for example:

i dont know whether any of these support USB passthrough as i dont need this feature anymore (solved my problem by using a different machine), but someone could experiment with these and maybe find an alternative solution to this (very old) issue

@iot49
Copy link

iot49 commented Dec 5, 2023 via email

@dracoventions
Copy link

dracoventions commented Jan 17, 2024

Another PSA: https://christopherjmcclellan.wordpress.com/2019/04/21/using-usb-with-docker-for-mac/ describes how to USB forward to a docker daemon run in VirtualBox on macOS. I haven't personally tried yet.

@lmapii
Copy link

lmapii commented Jan 17, 2024

Another PSA: https://christopherjmcclellan.wordpress.com/2019/04/21/using-usb-with-docker-for-mac/ describes how to USB forward to a docker daemon run in VirtualBox on macOS. I haven't personally tried yet.

This uses docker-machine which is now also deprecated. Had a running setup with that in 2019 as well, now docker-machine is gone too. See docker/roadmap#245.

@rubberduck203
Copy link

I’m actually the author of that blog.
I’ve not tested that method recently and even at the time it only really worked with certain uart chips. Basically, use at your own caution.

@rubberduck203
Copy link

I also don’t know what the odds of this are, but this xkcd dropped today.

https://xkcd.com/2881

@reconbot
Copy link
Author

I thought I muted this thread long ago but you just made me laugh at loud, so I guess I'm glad I didn't. I hope everyone here is making cool stuff and having fun doing it.

-Francis

@ginjo
Copy link

ginjo commented Jan 21, 2024

Was completely pointless me buying a zigbee adapter to run on my Mac then...! Will be returning it until this is fixed (if ever...!)

Same here, bought a Zooz dongle figuring I could connect to my zwave thermostat from my Mac. Oh well, another perfectly good tech gadget for the maybe-useful-in-the-future box in the basement.

Edit: Just to update, I've solved my immediate problem by using ser2net to host the USB dongle on a TCP port. I connect to that with zwave-js-ui (Docker), and finally with Home Assistant (Docker). It's been running without issue for a week now.

@jemdiggity
Copy link

Boooo!

@jwise
Copy link

jwise commented Jan 29, 2024

@jemdiggity wrote:

Boooo!

Do not do this. It is not kind to the people who spend their life writing software that you will use for free.

-- your friend from xkcd 2881, who has also been an open source project maintainer on occasion.

@mrwonko
Copy link

mrwonko commented Feb 8, 2024

WSL uses usbipd to tunnel USB over IP, maybe that would be an acceptable workaround for some here? It will require custom logic inside the docker image to un-tunnel it, so it's not fully transparent.

@christiandennis
Copy link

Same here, bought a Zooz dongle figuring I could connect to my zwave thermostat from my Mac. Oh well, another perfectly good tech gadget for the maybe-useful-in-the-future box in the basement.

Edit: Just to update, I've solved my immediate problem by using ser2net to host the USB dongle on a TCP port. I connect to that with zwave-js-ui (Docker), and finally with Home Assistant (Docker). It's been running without issue for a week now.

hey @ginjo, I'm in the same exact situation. Do mind sharing how you got that working?

@ginjo
Copy link

ginjo commented Feb 14, 2024

@christiandennis , Sure I'll try to describe the essential parts here, if it's not too lengthy. I'll come back and edit this comment when I get something written up.

Update: Ok here's a gist with a basic writeup describing my Home Assistant setup using zwave-js-ui and ser2net to access a USB z-wave stick over a TCP port from a Docker container. It's not an exhaustive writeup, but hopefully it will get you most of the way there.

More specifically, this shows how to use ser2net to host a USB device on a TCP port, so it can be accessed from within a Docker container.

basic_ha_zwave_docker_setup.md

Update 2024-05-06:
Since my dev machine is a Mac, the ser2net solution (or something like it) is still the workaround that has performed very well for me.

My production server is a linux machine (rPi), with my docker services running in Swarm mode. Since Swarm mode does not allow access to usb ports, even on linux, I used the ser2net workaround here as well. All good, however there is an even better way that is pure Docker:

Have your swarm container launch a privileged non-swarm docker container which will allow access to the USB port. Some call this docker-in-docker, but it's more like docker-from-docker or docker-on-docker. Your swarm service container is merely a wrapper to launch a plain docker run ... container as privileged. That privileged container runs the software/app/driver/whatever that needs physical access to the USB port. It sounds clumsy, but I've run this kind of workaround for various solutions for years, and it works really well. The 'inner' container is not part of the swarm (though you can put it on the swarm's network), but its lifecycle is still managed by the parent swarm container. So from an admin POV, it starts up and shuts down as if it's part of the swarm.

@ajay-bhargava
Copy link

I too have run into this issue when attempting to mount nRF52480 Nordic Semiconductor DevKits while simultaneously trying to preserve my Mac / containerize the necessary toolchains needed to develop on that device. As commented upon for the last 8 years, there is a mismatch in the /dev/ device list between the host and the container.

@Soran-i
Copy link

Soran-i commented Mar 28, 2024

I am new to Docker and have been trying to use openocd to connect to a serial device that I have. It's crazy to me that this thread is that old with no fix in sight.

boo 👎

@KrogerWalt
Copy link

I too have run into this issue when attempting to mount nRF52480 Nordic Semiconductor DevKits while simultaneously trying to preserve my Mac / containerize the necessary toolchains needed to develop on that device. As commented upon for the last 8 years, there is a mismatch in the /dev/ device list between the host and the container.

Unfortunately docker is useless for anything other than building in a cloud pipeline. All my Nordic stuff has to be done an a VM because Docker can't do virtualization on a Mac.

@miamilabs
Copy link

The "host" was been now add into docker after the ticket was been open for 6? years.
Hope this one get some attention in next 10 years so i can throw away my rasperry and move everything my my mac minis...

@Johnyb0223
Copy link

Spent all day wondering what I was doing wrong. Found this. Glad I'm not the only one. Can't believe this has been a problem for so long. All I've ever heard is how great docker is suppose to be, and it is in some ways but this is a pretty big deal breaker for me. I have no experience with other virtualization software but I guess there is always a time to learn.

@HomeACcessoryKid
Copy link

HomeACcessoryKid commented May 6, 2024 via email

@ucs308
Copy link

ucs308 commented May 7, 2024

Spent all day wondering what I was doing wrong. Found this. Glad I'm not the only one. Can't believe this has been a problem for so long. All I've ever heard is how great docker is suppose to be, and it is in some ways but this is a pretty big deal breaker for me. I have no experience with other virtualization software but I guess there is always a time to learn.

What are you trying to do? I am doing embedded work and using ESP-IDF and using RFC2217 (TelNet) to flash a dev board from inside a running docker instance connected to my Mac. It is a PIA but for now it works.. I use the serial monitor the same way. Here is a link to the ESP-IDF document.

@AIWintermuteAI
Copy link

@ucs308 you saved me a lot of time, thanks!
Worked like a charm for ESP32.

@0xAl3xH
Copy link

0xAl3xH commented May 22, 2024

stumbled back on this problem only to find I've visited this page a few years ago and forgotten. See you in another few years everyone and maybe we should get a beach house to celebrate if/when this becomes supported

@lesterlo
Copy link

It seems there is a usbcontrollers API on the macOS 15.0 beta

https://developer.apple.com/documentation/virtualization/vzvirtualmachineconfiguration/4360569-usbcontrollers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests