Skip to content

Commit 08776e9

Browse files
committed
Instead of silently skipping user creation, it renames the existing "ubuntu" user/group to "vscode" so that USER vscode resolves correctly
1 parent 3ae3360 commit 08776e9

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,18 @@ RUN curl -fsSL https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/bi
4444
ARG USERNAME=vscode
4545
ARG USER_UID=1000
4646
ARG USER_GID=$USER_UID
47-
RUN if ! getent group $USER_GID >/dev/null; then groupadd --gid $USER_GID $USERNAME; fi && \
48-
if ! getent passwd $USER_UID >/dev/null; then useradd --uid $USER_UID --gid $USER_GID -m $USERNAME; fi && \
47+
RUN EXISTING_GROUP=$(getent group $USER_GID | cut -d: -f1 || echo ""); \
48+
EXISTING_USER=$(getent passwd $USER_UID | cut -d: -f1 || echo ""); \
49+
if [ -n "$EXISTING_GROUP" ] && [ "$EXISTING_GROUP" != "$USERNAME" ]; then \
50+
groupmod -n $USERNAME $EXISTING_GROUP; \
51+
elif [ -z "$EXISTING_GROUP" ]; then \
52+
groupadd --gid $USER_GID $USERNAME; \
53+
fi && \
54+
if [ -n "$EXISTING_USER" ] && [ "$EXISTING_USER" != "$USERNAME" ]; then \
55+
usermod -l $USERNAME -d /home/$USERNAME -m $EXISTING_USER; \
56+
elif [ -z "$EXISTING_USER" ]; then \
57+
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME; \
58+
fi && \
4959
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \
5060
chmod 0440 /etc/sudoers.d/$USERNAME
5161

0 commit comments

Comments
 (0)