Skip to content

Commit 451e001

Browse files
committed
Try fix devcontainer
1 parent bce93df commit 451e001

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.devcontainer/Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ RUN apt-get update \
1919
&& apt-get -y install git iproute2 procps lsb-release \
2020
#
2121
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
22-
&& groupadd --gid $USER_GID $USERNAME \
23-
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
22+
# Create group if it doesn't exist (handle case where GID already exists)
23+
&& if ! getent group $USERNAME > /dev/null 2>&1; then \
24+
groupadd --gid $USER_GID $USERNAME 2>/dev/null || \
25+
(EXISTING_GROUP=$(getent group $USER_GID | cut -d: -f1) && groupmod -n $USERNAME $EXISTING_GROUP); \
26+
fi \
27+
# Create user if it doesn't exist (handle case where UID already exists)
28+
&& if ! getent passwd $USERNAME > /dev/null 2>&1; then \
29+
useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME 2>/dev/null || \
30+
(EXISTING_USER=$(getent passwd $USER_UID | cut -d: -f1) && usermod -l $USERNAME -d /home/$USERNAME -m $EXISTING_USER); \
31+
fi \
2432
# [Optional] Add sudo support for the non-root user
2533
&& apt-get install -y sudo \
2634
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
// Use 'postCreateCommand' to run commands after the container is created.
3131
"postCreateCommand": "dotnet tool restore && dotnet restore",
3232

33-
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
34-
"remoteUser": "root"
33+
// Use the non-root user created in the Dockerfile. More info: https://aka.ms/dev-containers-non-root.
34+
"remoteUser": "vscode"
3535
}

0 commit comments

Comments
 (0)