Use the current user and his group(s) inside the container:
docker run
-ti
--rm
-u `id -u`
-v /etc/group:/etc/group
-v /etc/passwd:/etc/passwd
alpine
/bin/sh
If you want to set a specific group my_primary_group
as primary group:
docker run
-ti
--rm
-u `id -u`:my_primary_group
--group-add `id -G | sed "s/ / --group-add /g"`
-v /etc/group:/etc/group
-v /etc/passwd:/etc/passwd
alpine
/bin/sh