Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a non sudo user in the docker image #4

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]