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.
CAPTCHA
             oooooo   oooo  ooo        ooooo                         oooooo     oooo 
`888. .8' `88. .888' `888. .8'
oo.ooooo. `888. .8' 888b d'888 oooooooo .oooo. `888. .8'
888' `88b `888.8' 8 Y88. .P 888 d'""7d8P `P )88b `888. .8'
888 888 `888' 8 `888' 888 .d8P' .oP"888 `888.8'
888 888 888 8 Y 888 .d8P' .P d8( 888 `888'
888bod8P' o888o o8o o888o d8888888P `Y888""8o `8'
888
o888o
Enter the code depicted in ASCII art style.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.