RUN useradd -ms /bin/bash newuser
USER newuser
WORKDIR /home/newuser
# Create the user
ARG USER_ID=1005
ARG GROUP_ID=1006
ARG USERNAME=<user_name>
RUN groupadd --gid $GROUP_ID $USERNAME
&& useradd --uid $USER_ID --gid $GROUP_ID -m $USERNAME
#
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
&& apt-get update
&& apt-get install -y sudo
&& echo $USERNAME ALL=(root) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
&& chmod 0440 /etc/sudoers.d/$USERNAME
USER $USERNAME
# OR TLDR
RUN groupadd -r <group> && useradd --no-log-init -r -g <group> <user>
USER <user>