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

running with docker #1104

Closed
waspinator opened this issue Mar 4, 2020 · 7 comments
Closed

running with docker #1104

waspinator opened this issue Mar 4, 2020 · 7 comments

Comments

@waspinator
Copy link

I'm trying to run ros within docker containers, but I'm having issue passing through the realsense hardware paths because they contain colons. Can you reconfigure the device names to not contain colons?

version: "3"

services:

  ros-master:
    image: ros:kinetic-ros-core
    command: stdbuf -o L roscore
    networks:
      - ros
    restart: always

  realsense:
    build:
      context: ./docker
      dockerfile: ros-realsense.dockerfile
    environment:
      - "ROS_MASTER_URI=http://ros-master:11311"
      - "ROS_HOSTNAME=realsense"
    devices:
      - "/dev/HID-SENSOR-2000e1.3.auto:/dev/HID-SENSOR-2000e1.3.auto"
      - "/dev/iio:device0:/dev/iio:device0"
      - "/dev/iio:device1:/dev/iio:device1"
      - "/dev/video0:/dev/video0"
      - "/dev/video1:/dev/video1"
      - "/dev/video2:/dev/video2"
      - "/dev/video3:/dev/video3"
      - "/dev/video4:/dev/video4"
      - "/dev/video5:/dev/video5"
    networks:
      - ros
    restart: always
    command: roslaunch realsense2_camera rs_camera.launch


networks:
  ros:
    driver: bridge
@waspinator
Copy link
Author

adding the privileged: true option and sharing all of /dev seems to be working...

version: "3"

services:

  ros-master:
    image: ros:kinetic-ros-core
    command: stdbuf -o L roscore
    networks:
      - ros
    restart: always


  realsense:
    privileged: true
    build:
      context: ./docker
      dockerfile: ros-realsense.dockerfile
    environment:
      - "ROS_MASTER_URI=http://ros-master:11311"
      - "ROS_HOSTNAME=realsense"
    devices:
      - "/dev:/dev"
    networks:
      - ros
    restart: always
    command: roslaunch realsense2_camera rs_camera.launch

networks:
  ros:
    driver: bridge

@130s
Copy link

130s commented Nov 5, 2020

I concur the finding in #1104 (comment). At my work we've been using Realsense driver (both librealsense and realsense2_camera) running within Docker container for more than a year with that.

@130s
Copy link

130s commented Nov 5, 2020

Also related (and more active) discussion IntelRealSense/librealsense#3849

@RealSenseSupport
Copy link
Collaborator

Hi,

Will you be needing further help with this? Was @130s suggestion helpful?

If we don’t hear from you in 7 days, this issue will be closed.

Thanks

@ll-nick
Copy link

ll-nick commented Apr 21, 2022

So just an FYI for future travelers:
I didn't like mounting the entire /dev directory and giving the container privileged access. However, there I couldn't find any other way of doing online.

The following solution also works, although I have to use some bash magic, so I run my docker image using a run.sh script. Here's the TL;DR version, for more details see below:

TL;DR

#!/bin/bash

BUS=$(lsusb | grep 8086 | cut -d " " -f 2)
PORT=$(lsusb | grep 8086 | cut -d " " -f 4 | cut -d ":" -f 1)

if [ ! -z "$PORT" ];
docker run \
  --volume /dev/bus/usb/$BUS/$PORT:/dev/bus/usb/$BUS/$PORT \
  --device-cgroup-rule "c 189:* rmw" \
  <a bunch more flags> \
  <img_name>

Explanation

Instead of mounting the entire /dev, I only mount the specific device. Finding that wasn't super easy but using the bus and port info I get from lsusb, I can do that. E.g. lsusb delivers

Bus 004 Device 002: ID 8086:0b3a Intel Corp. Intel(R) RealSense(TM) Depth Camera 435i

You'll find the realsense at /dev/bus/usb/004/002 with 004 being the first number of above output and 002 the second number.

To gain read/write access, instead of using the --privileged flag, I use --device-cgroup-rule "c 189:* rmw" where 189 is the major number of the USB bus. For more details see e.g. this guide.

@solosuper
Copy link

... where 189 is the major number of the USB bus.

I knew nothing about this magic number 189, so for other future travelers like me:

ls -l /dev/bus/usb/${BUS}/${PORT} shows something like

crw-rw-r-- 1 root root 189, 256 march  30 12:18 /dev/bus/usb/004/002

and there is the 189 again. The c in the beginning of the line is telling us the file type, where file /dev/bus/usb/${BUS}/${PORT}
is even more explicit

/dev/bus/usb/004/002: character special (189/256)

Googling "file character special" tells me (emphasis mine) that

A character special file is a file that provides access to an input/output device. Examples of character special files are: a terminal file, a NULL file, a file descriptor file, or a system console file. Each character special file has a device major number, which identifies the device type, and a device minor number, which identifies a specific device of a given device type.

That was all I could find out about 189, and I'm kind of satisfied :) If someone has links to more complete information, please feel free to enlighten me (or us).

@ciandonovan
Copy link

I'm trying to run ros within docker containers, but I'm having issue passing through the realsense hardware paths because they contain colons. Can you reconfigure the device names to not contain colons?

version: "3"

services:

  ros-master:
    image: ros:kinetic-ros-core
    command: stdbuf -o L roscore
    networks:
      - ros
    restart: always

  realsense:
    build:
      context: ./docker
      dockerfile: ros-realsense.dockerfile
    environment:
      - "ROS_MASTER_URI=http://ros-master:11311"
      - "ROS_HOSTNAME=realsense"
    devices:
      - "/dev/HID-SENSOR-2000e1.3.auto:/dev/HID-SENSOR-2000e1.3.auto"
      - "/dev/iio:device0:/dev/iio:device0"
      - "/dev/iio:device1:/dev/iio:device1"
      - "/dev/video0:/dev/video0"
      - "/dev/video1:/dev/video1"
      - "/dev/video2:/dev/video2"
      - "/dev/video3:/dev/video3"
      - "/dev/video4:/dev/video4"
      - "/dev/video5:/dev/video5"
    networks:
      - ros
    restart: always
    command: roslaunch realsense2_camera rs_camera.launch


networks:
  ros:
    driver: bridge

I've submitted a pull request to the upsteam librealsense that should allow your original docker-compose to work as-is, without requiring the --privileged flag or needing the --device-cgroup-rule "c 189:* rmw" flag since that gives access to the entire USB which isn't ideal.

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

No branches or pull requests

6 participants