Skip to content

Commit

Permalink
feat: allow specifying uid and gid
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyPorthouse committed Nov 13, 2023
1 parent b56929e commit 00b8eef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ RUN apt update \
&& apt install -y jq \
&& rm -rf /var/lib/apt/lists/*

RUN adduser --disabled-password --uid 1000 --shell /bin/bash --gecos "" minecraft \
&& addgroup minecraft users

EXPOSE 25565

WORKDIR /minecraft
Expand Down
23 changes: 22 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ set -e

JAR_NAME="server-${MINECRAFT_VERSION}.jar"

PUID=${PUID:-1000}
PGID=${PGID:-1000}
USER=${USER:-"minecraft"}

if [ ! "$(id -u "${USER}")" -eq "$PUID" ]; then usermod -o -u "$PUID" "${USER}" ; fi
if [ ! "$(id -g "${USER}")" -eq "$PGID" ]; then groupmod -o -g "$PGID" "${USER}" ; fi

echo "
-----------------------------------
GID/UID
-----------------------------------
User uid: $(id -u "${USER}")
User gid: $(id -g "${USER}")
-----------------------------------
"

if [ ! -f "$JAR_NAME" ]; then
echo "Downloading Minecraft";

Expand All @@ -18,4 +34,9 @@ fi
echo "Accepting EULA"
echo "eula=true" > eula.txt

java ${JAVA_OPTS} -jar "$JAR_NAME" nogui
chown -R "${USER}":"${USER}" /minecraft


COMMAND="${*:-"cd /minecraft; $(which java) ${JAVA_OPTS} -jar $JAR_NAME nogui"}"

su -l "${USER}" -c "$COMMAND"

0 comments on commit 00b8eef

Please sign in to comment.