docker_logo.png

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(com.apple.sharepoint.group.1),33(_appstore),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),400(com.apple.access_remote_ae)

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.
              ooo        ooooo   .oooooo..o  ooooooooo.     o8o     oooooooo 
`88. .888' d8P' `Y8 `888 `Y88. `"' dP"""""""
ooo. .oo. 888b d'888 Y88bo. 888 .d88' oooo d88888b.
`888P"Y88b 8 Y88. .P 888 `"Y8888o. 888ooo88P' `888 `Y88b
888 888 8 `888' 888 `"Y88b 888 888 ]88
888 888 8 Y 888 oo .d8P 888 888 o. .88P
o888o o888o o8o o888o 8""88888P' o888o o888o `8bd88P'


Enter the code depicted in ASCII art style.