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.