Skip to content

Commit a5aaff0

Browse files
committed
feat: enhance user/group setup in Dockerfiles to handle UID/GID conflicts more robustly
1 parent 6c074dd commit a5aaff0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Dockerfile.alpine

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ RUN if [ "$TARGETARCH" = "arm64" ]; then \
7070
# Setup User (with UID/GID conflict handling)
7171
RUN if getent passwd ${UID} > /dev/null 2>&1; then \
7272
EXISTING_USER=$(getent passwd ${UID} | cut -d: -f1); \
73+
EXISTING_GROUP=$(getent passwd ${UID} | cut -d: -f4); \
7374
deluser ${EXISTING_USER} && \
75+
if getent group ${GID} > /dev/null 2>&1; then \
76+
GROUP_NAME=$(getent group ${GID} | cut -d: -f1); \
77+
delgroup ${GROUP_NAME}; \
78+
fi; \
7479
addgroup -S -g ${GID} ${USER} && \
7580
adduser -S -D -h ${HOME} -u ${UID} -G ${USER} ${USER}; \
7681
else \

Dockerfile.alpine-liberica

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ RUN if [ "$TARGETARCH" = "arm64" ]; then \
7070
# Setup User (with UID/GID conflict handling)
7171
RUN if getent passwd ${UID} > /dev/null 2>&1; then \
7272
EXISTING_USER=$(getent passwd ${UID} | cut -d: -f1); \
73+
EXISTING_GROUP=$(getent passwd ${UID} | cut -d: -f4); \
7374
deluser ${EXISTING_USER} && \
75+
if getent group ${GID} > /dev/null 2>&1; then \
76+
GROUP_NAME=$(getent group ${GID} | cut -d: -f1); \
77+
delgroup ${GROUP_NAME}; \
78+
fi; \
7479
addgroup -S -g ${GID} ${USER} && \
7580
adduser -S -D -h ${HOME} -u ${UID} -G ${USER} ${USER}; \
7681
else \

0 commit comments

Comments
 (0)