From 8f73556117ce6ee2dd251182961e3930c45bb2b6 Mon Sep 17 00:00:00 2001 From: Patrick Rizzardi <35274364+RedactDigital@users.noreply.github.com> Date: Mon, 26 Jun 2023 23:26:10 -0400 Subject: [PATCH] Create a non sudo user in the docker image --- Dockerfile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0f439d..35fd77a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,18 @@ FROM ubuntu:22.04 +ENV USER=minecraft +ENV UID=1000 +ENV GID=1000 ENV WORKDIR=/minecraft # Vars used in scripts and entrypoint ENV TMUX_SESSION=minecraft ENV PROJECT=paper +# Create user and group +RUN groupadd --gid ${GID} ${USER} && \ + useradd --create-home --shell /bin/bash --uid ${UID} --gid ${GID} ${USER} && \ + usermod -aG sudo ${USER} + # Install dependencies RUN apt update && apt upgrade -y && apt install -y --no-install-recommends \ vim \ @@ -35,10 +43,11 @@ RUN apt-get -y autoremove \ && rm -rf /tmp/* \ && rm -rf /var/tmp/* +USER ${USER} WORKDIR $WORKDIR # Copy scripts folder and make them executable -COPY scripts scripts +COPY --chown=${USER}:${USER} scripts scripts RUN chmod +x scripts/* # Add commands to bashrc @@ -48,7 +57,7 @@ RUN echo "alias start='bash $WORKDIR/scripts/start.sh'" >> ~/.bashrc && \ echo "alias debug='bash $WORKDIR/scripts/debug.sh'" >> ~/.bashrc # Copy entrypoint -COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh +COPY --chown=${USER}:${USER} entrypoint.sh /home/${USER}/entrypoint.sh +RUN chmod +x /home/${USER}/entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["sh", "-c", "/home/$USER/entrypoint.sh"]