Skip to content

Commit

Permalink
Create a non sudo user in the docker image (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickrizzardi authored Jun 27, 2023
1 parent 7f00127 commit fa92cd5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -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"]

0 comments on commit fa92cd5

Please sign in to comment.