Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

add user to dockerfile

# 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>
Source by code.visualstudio.com #
 
PREVIOUS NEXT
Tagged: #add #user #dockerfile
ADD COMMENT
Topic
Name
7+7 =