Docker Update 3

This commit is contained in:
2026-01-10 23:07:31 +00:00
parent bbd051dcf5
commit f03b2d627f

View File

@@ -116,16 +116,22 @@ ARG USERNAME=pilot
ARG USER_UID=1000 ARG USER_UID=1000
ARG USER_GID=1000 ARG USER_GID=1000
# Create user - handle case where GID/UID 1000 may already exist # Create user - remove any existing user/group with same UID/GID first
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y sudo \ && apt-get install -y sudo \
# Create group if it doesn't exist, or use existing # Remove existing user with UID 1000 if it exists (e.g., 'ubuntu' user)
&& (getent group $USER_GID || groupadd --gid $USER_GID $USERNAME) \ && existing_user=$(getent passwd $USER_UID | cut -d: -f1) \
# Create user if doesn't exist && if [ -n "$existing_user" ] && [ "$existing_user" != "$USERNAME" ]; then \
&& (id -u $USER_UID >/dev/null 2>&1 || useradd --uid $USER_UID --gid $USER_GID -m $USERNAME) \ userdel -r "$existing_user" 2>/dev/null || true; \
# Ensure home directory exists and has correct ownership fi \
&& mkdir -p /home/$USERNAME \ # Remove existing group with GID 1000 if it exists
&& chown $USER_UID:$USER_GID /home/$USERNAME \ && existing_group=$(getent group $USER_GID | cut -d: -f1) \
&& if [ -n "$existing_group" ] && [ "$existing_group" != "$USERNAME" ]; then \
groupdel "$existing_group" 2>/dev/null || true; \
fi \
# Now create our user and group
&& groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m -s /bin/bash $USERNAME \
# Add sudo permissions # Add sudo permissions
&& echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \ && echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME \