User created in Dockerfile with multiple groups does not have additional groups inside the docker image

Hi Docker Gurus,

I have seeing a weird problem when creating a docker image. I have the following RUN instruction in my Dockerfile:

RUN addgroup -S ubuntu && \
    adduser -S -D ubuntu -h /home/ubuntu -s /bin/bash -G ubuntu && \
    addgroup ubuntu root

But when I use the docker image in a Concourse CICD, the user ubuntu has only one group:

bash-5.0$ id
uid=101(ubuntu) gid=102(ubuntu) groups=102(ubuntu)

But in the container, when I use su command to login as ubuntu again, all the groups are as expected for ubuntu.

bash-5.0$ sudo su - ubuntu
ACMv1-: id
uid=101(ubuntu) gid=102(ubuntu) groups=102(ubuntu),0(root)

I expected the root and ubuntu groups to be associated with the user ubuntu even before trying su command. Appreciate any help in this matter.

It would be important to know the base image. I guess it is alpine, since addgroup works differently in a standard ubuntu image. If I am right, it is a little weird to create an ubuntu user in an Alpine image, although I am sure you have a good reason.

Without the base image, I can only share one of my old experiences. The only time I had a similar problem (not in containers) when I installed a knew Linux distribution, probably Kubuntu and an authentication module (PAM) caused that I could not give sudo permission to my user until I disabled that module. I don’t remember the details…