Coder Social home page Coder Social logo

docker-usb-sync's Introduction

Working with ephemeral (dynamically created) USB devices in Docker

In case you need to run some Android flashing utils like heimdall in Docker you need to run your container with following options of your choice.

There are two of implementation ways of this:

  1. Create cgroup rule and sync devices in container by udev trigger (as described below and what I've made)
  2. Run docker container with --priviliged -v /dev/bus/usb (not safe)

This repository contains an implementation of moby/moby#22563 PR:

Dealing with dynamically created devices (--device-cgroup-rule) Devices available to a container are assigned at creation time. The assigned devices will both be added to the cgroup.allow file and created into the container once it is run. This poses a problem when a new device needs to be added to a running container. One of the solution is to add a more permissive rule to a container allowing it access to a wider range of devices. For example, supposing our container needs access to a character device with major 42 and any number of minor number (added as new devices appear), the following rule would be added: docker create --device-cgroup-rule='c 42:* rmw' -name my-container my-image Then, a user could ask udev to execute a script that would docker exec my-container mknod newDevX c 42 the required device when it is added. NOTE: initially present devices still need to be explicitely added to the create/run command

1. Add sync script:

cp docker-usb-sync.py /usr/bin/docker_device_sync.py

Don't forget to change container name in script.

2. Create new udev rule:

ACTION=="add", SUBSYSTEM=="usb", RUN+="/usr/bin/docker_device_sync.py"
sudo service udev restart

3. Run container:

docker run --rm -d --device=/dev/bus/usb --device-cgroup-rule='c 189:* rmw' <image_name>

4. Device reboot:

adb reboot download
heimdall close-pc-screen

Now at every host device reconnect, a device also will be mapped into a container by our script triggered by udev.

docker-usb-sync's People

Contributors

pbelskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

docker-usb-sync's Issues

License?

Thanks for sharing this script! I'm trying to solve a problem with dynamic devices in Docker and I'd like to use or adapt this script. If that's ok could you please add a license? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.