Recently I faced with a bug when my docker containers didnt success building in macos. First my thoughts was that shell command to getting UID and GID was not working correctly. But I did a test in MacOs in Virtualbox and everything was fine.
The command which end up with error was:

RUN echo "Creating user & group" \
  && groupadd -g "$GID" drupal \
  && useradd -r -u "$UID" -g "$GID" -m drupal

The command should map local OS user UID:GID to container's user. By default user in Linux has a user id and groupd id started from 1000. But in MacOs there is another situation. There are predefined groups for local users which are less than 1000 number.
To get the groups list:

$ id
uid=501(currentuser) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),701(,33(_appstore),100(_lpoperator),204(_developer),250(_analyticsusers),395(,398(,399(,400(

In this case we get the error when tyring to create the group which already present in container.
Small fix will remove the error and set correct credentials mapping in container:

RUN echo "Creating user & group" \
  && [ $(getent group "$GID") ] || groupadd -g "$GID" drupal \
  && useradd -r -u "$UID" -g "$GID" -m drupal

Add new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed.
     o8o    .oooooo.     .ooooo.    oooo               .o    ooo        ooooo 
`"' d8P' `Y8b d88' `8. `888 .d88 `88. .888'
oooo 888 Y88.. .8' 888 .oo. .d'888 888b d'888
`888 888 `88888b. 888P"Y88b .d' 888 8 Y88. .P 888
888 888 .8' ``88b 888 888 88ooo888oo 8 `888' 888
888 `88b ooo `8. .88P 888 888 888 8 Y 888
888 `Y8bood8P' `boood8' o888o o888o o888o o8o o888o
.o. 88P
Enter the code depicted in ASCII art style.