简体   繁体   中英

How to access USB ports from Docker Container on Mac OS

I have created a Docker container for building and testing my Flutter apps. I want to connect my mobile device to the USB port of my Macbook and run Flutter apps directly on the device from the Docker container. But, I am unable to access the USB ports from the container and receiving this error.

错误

I am using Remote Development extension inside my VS Code for running the container.

The devcontainer.json file is attached below:

{
    "name": "flutter_docker",
    "context": "..",
    "dockerFile": "../Dockerfile",
    "remoteUser": "developer",
    "mounts": [
        "source=/dev/bus/usb,target=/dev/bus/usb,type=bind"
    ],
    "settings": {
        "terminal.integrated.shell.linux": null
    },
    "runArgs": ["--privileged"],
    "extensions": ["dart-code.flutter"],
    "workspaceMount": "source=${localWorkspaceFolder}/workspace,target=/home/developer/workspace,type=bind,consistency=delegated",
    "workspaceFolder": "/home/developer/workspace"
}

Whenever I remove the mounts from the json file, it runs fine without any error.

Removing this line:

"mounts": [
    "source=/dev/bus/usb,target=/dev/bus/usb,type=bind"
],

Dockerfile:

FROM ubuntu:18.04

# Prerequisites
RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget

# Setup new user
RUN useradd -ms /bin/bash developer
USER developer
WORKDIR /home/developer

# Prepare Android directories and system variables
RUN mkdir -p Android/Sdk
ENV ANDROID_SDK_ROOT /home/developer/Android/Sdk
RUN mkdir -p .android && touch .android/repositories.cfg

# Setup Android SDK
RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN unzip sdk-tools.zip && rm sdk-tools.zip
RUN mv tools Android/Sdk/tools
RUN cd Android/Sdk/tools/bin && yes | ./sdkmanager --licenses
RUN cd Android/Sdk/tools/bin && ./sdkmanager "build-tools;29.0.2" "patcher;v4" "platform-tools" "platforms;android-29" "sources;android-29"

# Download Flutter SDK
RUN git clone https://github.com/flutter/flutter.git
ENV PATH "$PATH:/home/developer/flutter/bin"

# Run basic check to download Dark SDK
RUN flutter doctor

Currently, there is an open bug in GitHub about USB Passthrough. Also it was mentioned in the Docker FAQs that it is not possible to pass through a USB device:

Unfortunately, it is not possible to pass through a USB device (or a serial port) to a container as it requires support at the hypervisor level.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM