7

I have a script that communicates over serial port (/dev/ttyUSB0). I want to run it from within a Docker image. However I don't seem to have permissions to do it from within the image. I follow these steps:

On my host, if I run ln -l /dev/ttyUSB0 I get:

crw-rw---- 1 root dialout 188, 0 jul  2 14:34 /dev/ttyUSB0

Good, it means that in order to read/write to it, I need to be either root, or part of the dialout group.

I become member of this group in my host:

$ sudo usermod -aG dialout $(whoami)

Then I log out and log in again to make this effective.

After that, I verify that I can communicate perfectly with /dev/ttyUSB0 from my host. However if I run the docker image:

docker run --user=1000:1000 --rm=true --tty=true --privileged=true --device=/dev/ttyUSB0 --volume=<my_dir>:<my_dir> --workdir=<my_dir> <my_docker_image> <my_script>

Then it complains:

can't open device "/dev/ttyUSB0": Permission denied

However if I use: --user=1000:20, then it works fine. The group 20 is the dialout group.

Now my question:

Why does Docker not understand that my user (1000) and group (1000) is part of the dialout group?

This was working when I used the old docker (apt-get install docker-io, docker-engine), but after updating to the new Docker CE this stopped working.

Setup:

  • Ubuntu 16.04.2 LTS Kernel 4.4.0-83-generic.
  • Docker version: Docker version 17.06.0-ce, build 02c1d87.

Thanks!

user1011113
  • 1,114
  • 8
  • 27
  • From inside the container, your processes won't be able to see your host tc's user and group information. This is because the container will have its own /etc/passwd and /etc/group files, which may not match what your host has. – programmerq Jul 03 '17 at 16:04
  • 2
    Thanks! I also tried mounting those files with the `--volume` option, but it didn't work either. The solution was to pass `--group-add=dialout` to the `docker run` call – user1011113 Jul 04 '17 at 17:26

1 Answers1

1

As stated in a comment, The solution was to pass --group-add=dialout to the docker run call. However, be aware that when using docker images that provides a way to specify the user and group using an environment variable (usually -e PUID=<UID> -e PGID=<GID>) it overwrites that setting.