简体   繁体   中英

Docker Container USB Access

I have a python script for gps. In my python script it detects which serial port is connected. For instance, it can be ttyACM0 or ttyACM1. Script detects the serial port then starts the gps functions.

I would like to containerize this gps script with docker-compose as easy setup for end-user However, in local machine usb device is detected as /dev/ttyACM0 but gps container says it is detected as /dev/ttyACM1.

When I do cat /dev/ttyACM0 in my local machine the gps infos are shown but when I enter the command line cat /dev/ttyACM1 in docker container it says cat: /dev/ttyACM1: No such device or address

gps docker file

FROM python:3.8
WORKDIR /gps
RUN apt update -y && apt install libusb-1.0-0-dev -y
RUN pip3 install -U pip && pip3 install pynmea2==1.18.0 pyusb==1.2.1 pyserial==3.5

gps docker compose

version: '3.7'

services:
  gps:
    build:
      context: docker
      dockerfile: Dockerfile_gps
    privileged: true
    volumes:
      - ./gps:/gps
    restart: always
    working_dir: /gps
    command: python3 gps_operations.py

Solved the issue. Adding these lines fixed the problem.

environment:
  - UDEV=1
devices:
  - '/dev:/dev'

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