added Dockerfile, example compose and setup script

This commit is contained in:
prinoX
2025-02-08 14:24:12 +01:00
parent df0fe0bbed
commit 2dc0974957
5 changed files with 191 additions and 1 deletions
+28
View File
@@ -0,0 +1,28 @@
FROM alpine:latest
ENV MINECRAFT_VERSION= \
PAPER_BUILD="latest" \
EULA="false" \
MC_RAM=""
RUN apk update && \
apk add openjdk21-jre && \
apk add bash && \
apk add curl && \
apk add jq
RUN addgroup -S servergrp
RUN adduser -S server -G servergrp -D -u 1000
USER server
RUN mkdir /home/server/instance
#RUN chown -hR server:servergrp /home/server/instance
COPY setup.sh /home/server/
CMD ["bash", "/home/server/setup.sh"]
EXPOSE 25565
VOLUME /home/server/instance
+3 -1
View File
@@ -1,3 +1,5 @@
# papermc-server-docker # papermc-server-docker
Dockerized papermc minecraft server This repository rpovides a simple way to deploy a papermc minecraft server. Other solutions also make this happen, but this docker image adds the ability to prepare `*.prep` files with predefined whitelist entries and op entries to spin up the minecraft server with everything set up from the start.
The provides `setup.sh` script will install the latest papermc server for the selected minecraft version and generate the needed `whitelist.json` and `ops.json` files. To make this work simply provide a `whitelist.prep` and `op.prep` file with the desired usernames in the server folder, that you map in the docker container. The script will fetch the uuids of all usernames and setup the whitelist.
+22
View File
@@ -0,0 +1,22 @@
version: "3"
services:
server:
image: papermc-docker
container_name: YOUR_CONTAINER_NAME
restart: always
volumes:
- "YOUR_SERVER_LOCATION":/server:z
ports:
- "YOUR_PORT:25565"
environment:
SERVER_MEMORY: "2G"
EULA: "true"
SEED: "abc"
# provide a txt file with the usernames of the players to be whitelisted in the server folder to automatically add them to the whitelist
WHITELIST: "true"
MAX_PLAYERS: "20"
DIFFICULTY: "easy"
GAMEMODE: "survival"
MOTD: "A Dockerized Minecraft Server"
ENFORCE_SECURE_PROFILE: "false"
Executable
+138
View File
@@ -0,0 +1,138 @@
#!/bin/bash
# Enter server directory
cd /home/server/instance
# Set nullstrings back to 'latest'
: ${MINECRAFT_VERSION:='latest'}
# Lowercase these to avoid 404 errors on wget
MINECRAFT_VERSION="${MINECRAFT_VERSION,,}"
PROJECT="paper"
# prepare performance opts for java
JAVA_OPTS=" -XX:+UseG1GC -XX:+ParallelRefProcEnabled \
-XX:MaxGCPauseMillis=200 \
-XX:+UnlockExperimentalVMOptions \
-XX:+DisableExplicitGC \
-XX:+AlwaysPreTouch \
-XX:G1NewSizePercent=30 \
-XX:G1MaxNewSizePercent=40 \
-XX:G1HeapRegionSize=8M \
-XX:G1ReservePercent=20 \
-XX:G1HeapWastePercent=5 \
-XX:G1MixedGCCountTarget=4 \
-XX:InitiatingHeapOccupancyPercent=15 \
-XX:G1MixedGCLiveThresholdPercent=90 \
-XX:G1RSetUpdatingPauseTimePercent=5 \
-XX:SurvivorRatio=32 \
-XX:+PerfDisableSharedMem \
-XX:MaxTenuringThreshold=1 \
-Daikars.new.flags=true \
-Dusing.aikars.flags=https://mcflags.emc.gs"
# Get version information and build download URL and jar name
URL='https://papermc.io/api/v2/projects/paper'
if [[ $MINECRAFT_VERSION == latest ]]
then
# Get the latest MC version
MINECRAFT_VERSION=$(curl -s https://api.papermc.io/v2/projects/${PROJECT} | \
jq -r '.versions[-1]')
fi
LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${PROJECT}/versions/${MINECRAFT_VERSION}/builds | \
jq -r '.builds | map(select(.channel == "default") | .build) | .[-1]')
# update server.jar to latest stable
if [ "$LATEST_BUILD" != "null" ]; then
JAR_NAME=${PROJECT}-${MINECRAFT_VERSION}-${LATEST_BUILD}.jar
PAPERMC_URL="https://api.papermc.io/v2/projects/${PROJECT}/versions/${MINECRAFT_VERSION}/builds/${LATEST_BUILD}/downloads/${JAR_NAME}"
rm -f *.jar
# Download the latest Paper version
curl -o server.jar $PAPERMC_URL
echo "Download completed"
else
echo "No stable build for version $MINECRAFT_VERSION found :("
fi
# Update eula.txt with current setting
echo "eula=${EULA:-false}" > eula.txt
# Add RAM options to Java options if necessary
if [[ -n $SERVER_MEMORY ]]
then
JAVA_OPTS="-Xms${SERVER_MEMORY} -Xmx${SERVER_MEMORY} $JAVA_OPTS"
fi
# prepare server properties
SERVER_PROPERTIES=/server/server.properties
if [ -f /server/server.properties ]; then
mv $SERVER_PROPERTIES $SERVER_PROPERTIES.bkp
rm $SERVER_PROPERTIES
touch $SERVER_PROPERTIES
fi
if [ -f /server/whitelist.prep ]; then
echo -n "[" > /server/whitelist.json
cat /server/whitelist.prep | while read u
do
echo "Adding $u to whitelist"
# get uuid of user
uuid=$(curl -s https://api.mojang.com/users/profiles/minecraft/$u | jq -r '.id')
uuid=$(echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}")
if [[ $uuid == "null" ]]; then
echo "User $u not found. Skipping."
continue
fi
# write to whitelist.json
echo -n "{\"uuid\": \"$uuid\",\"name\": \"$u\"}" >> /server/whitelist.json;
done
echo "]" >> /server/whitelist.json
sed --in-place -e 's/}{/}, {/g' /server/whitelist.json
fi
if [ -f /server/op.prep ]; then
echo "true"
fi
if [[ -n $WHITELIST ]]; then
echo "white-list=$WHITELIST" >> $SERVER_PROPERTIES
fi
if [[ -n $SEED ]]; then
echo "seed=$SEED" >> $SERVER_PROPERTIES
fi
if [[ -n $MAX_PLAYERS ]]; then
echo "max-players=$MAX_PLAYERS" >> $SERVER_PROPERTIES
fi
if [[ -n $DIFFICULTY ]]; then
echo "difficulty=$DIFFICULTY" >> $SERVER_PROPERTIES
fi
if [[ -n $GAMEMODE ]]; then
echo "gamemode=$GAMEMODE" >> $SERVER_PROPERTIES
fi
if [[ -n $MOTD ]]; then
echo "motd=$MOTD" >> $SERVER_PROPERTIES
fi
if [[ -n $ENFORCE_SECURE_PROFILE ]]; then
echo "enforce-secure-profile=$ENFORCE_SECURE_PROFILE" >> $SERVER_PROPERTIES
fi
# Start server
exec java $JAVA_OPTS -jar "server.jar" nogui
View File