Home > Software engineering >  How to add a user to multiple groups in alpine linux
How to add a user to multiple groups in alpine linux

Time:06-24

I am creating a docker container using alpine as the base image and I have created a user using the following command: RUN adduser -u 5532 -s /bin/tcsh -D userA and I have already defined few groups as

RUN addgroup --gid 2076 groupA && \
    addgroup --gid 2077 groupB && \
    addgroup --gid 400 groupC

I am unable to assign the created user to multiple groups using adduser command. If I have multiple adduser command/instruction I am getting an error user userA is in use. Please let me know how can I assign a particular user to multiple groups in alpine linux.

Complete Dockerfile

FROM python:alpine3.16
RUN adduser -u 5532 -s /bin/tcsh -D userA
RUN addgroup --gid 2076 groupA && \
    addgroup --gid 2077 groupB && \
    addgroup --gid 400 groupC

cheers, DD

CodePudding user response:

The addgroup command can be used to add a user to a group by passing the user as first argument:

FROM python:alpine3.16
RUN adduser -D userA
RUN addgroup groupA && addgroup userA groupA
RUN addgroup groupB && addgroup userA groupB
USER userA

So first create a group with addgroup <GROUP> then add the user to the group with addgroup <USER> <GROUP>.

  • Related