Start a Docker container with a user permission and a USB device Start a Docker container with a user permission and a USB device docker docker

Start a Docker container with a user permission and a USB device


Have you checked the required access rights to the device? They are usually accessible by groups. Running using -u will only set your user with the group returned by id -g.

I also access devices and create files from a development-only container and solved this problem by creating a dedicated user within the container, including the required groups to access the devices.

Here is how I create this user for my development container in the Dockerfile:

# Create a non-root user with the same uid as on the host to allow proper file# permissions created from the container in volumes. Since it is not root, allow# calling sudo without password when required.ARG uidRUN useradd -M --uid $uid --user-group user --groups uucp \    && echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/user \    && echo 'Defaults exempt_group+=user' >> /etc/sudoers.d/user \    && chmod a=r,o= /etc/sudoers.d/userUSER user

These dockerfile instructions create a non-root user, with its own user group, and includes it in the uucp group to access TTY devices in Debian. The user id is passed as a Docker build argument (instruction ARG uid, plus Docker build option --build-arg uid=$(id -u)). I then add it as sudoer without a password (mostly to be able to sometimes run package management commands and try a few things).