From f5dbbcc2c67b8ca1c90977438114ae32d59565b8 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Tue, 14 Feb 2017 22:15:36 -0600 Subject: [PATCH] [mc] Use G1 GC by default and simplify max memory setting For #126 --- minecraft-server/Dockerfile | 2 +- minecraft-server/README.md | 7 ++++--- minecraft-server/start-minecraft.sh | 9 +++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile index 082bf85f..e89a9061 100644 --- a/minecraft-server/Dockerfile +++ b/minecraft-server/Dockerfile @@ -38,6 +38,6 @@ ENTRYPOINT [ "/start" ] ENV UID=1000 GID=1000 \ MOTD="A Minecraft Server Powered by Docker" \ - JVM_OPTS="-Xmx1024M -Xms1024M" \ + JVM_XX_OPTS="-XX:+UseG1GC" MAX_MEMORY="1G" \ TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED LEVEL=world PVP=true DIFFICULTY=easy \ LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= ONLINE_MODE=TRUE CONSOLE=true diff --git a/minecraft-server/README.md b/minecraft-server/README.md index 6cb9e052..f2495217 100644 --- a/minecraft-server/README.md +++ b/minecraft-server/README.md @@ -608,10 +608,11 @@ By default, server checks connecting players against Minecraft's account databas ### Memory Limit -The Java memory limit can be adjusted using the `JVM_OPTS` environment variable, where the default is -the setting shown in the example (max and min at 1024 MB): +By default the image declares a Java memory limit of 1 GB. That can be adjusted +higher (or lower) by setting the `MAX_MEMORY` environment variable. For example, +the following increases the memory limit to 8 GB: - docker run -e 'JVM_OPTS=-Xmx1024M -Xms1024M' ... + docker run -e MAX_MEMORY=8G ... ### /data ownership diff --git a/minecraft-server/start-minecraft.sh b/minecraft-server/start-minecraft.sh index c64372d7..c81e2fa8 100755 --- a/minecraft-server/start-minecraft.sh +++ b/minecraft-server/start-minecraft.sh @@ -490,6 +490,11 @@ else EXTRA_ARGS="" fi +if [[ ! -z $MAX_MEMORY ]]; then + # put prior JVM_OPTS at the end to give any memory settings there higher precedence + JVM_OPTS="-Xms${MAX_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}" +fi +set -x if [[ ${TYPE} == "FEED-THE-BEAST" ]]; then echo "Running FTB server modpack start ..." exec sh ${FTB_SERVER_START} @@ -497,8 +502,8 @@ else # If we have a bootstrap.txt file... feed that in to the server stdin if [ -f /data/bootstrap.txt ]; then - exec java $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS < /data/bootstrap.txt + exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS < /data/bootstrap.txt else - exec java $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS + exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS fi fi