Skip to content

Commit

Permalink
check for gid and uid first
Browse files Browse the repository at this point in the history
  • Loading branch information
JEMeyer committed Jun 2, 2024
1 parent 8b27b98 commit a20710b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ RUN npm install -g pm2
ARG USERNAME=appuser
ARG USER_UID=1000
ARG USER_GID=1000
RUN addgroup -g $USER_GID $USERNAME && \

# Check if the GID is already in use, if so, find an available GID
RUN if getent group $USER_GID; then \
USER_GID=$(getent group | awk -F: '{if ($3 >= 1000) print $3}' | sort -n | tail -1 | awk '{print $1+1}'); \
fi && \
if getent passwd $USER_UID; then \
USER_UID=$(getent passwd | awk -F: '{if ($3 >= 1000) print $3}' | sort -n | tail -1 | awk '{print $1+1}'); \
fi && \
addgroup -g $USER_GID $USERNAME && \
adduser --disabled-password -u $USER_UID -G $USERNAME $USERNAME && \
addgroup $USERNAME docker

Expand Down

0 comments on commit a20710b

Please sign in to comment.