Added fabric server

This commit is contained in:
Jef Roosens 2020-12-30 12:24:21 +01:00
parent dd46c27c70
commit 988420f915
5 changed files with 830 additions and 3 deletions

53
fabric/Dockerfile Normal file
View file

@ -0,0 +1,53 @@
FROM openjdk:8-jre
# This argument should be set when building
ARG VERSION
ARG JAR_URL="https://maven.fabricmc.net/net/fabricmc/fabric-installer/$VERSION/fabric-installer-$VERSION.jar"
WORKDIR /mc
# Download installer jar
ADD "https://maven.fabricmc.net/net/fabricmc/fabric-installer/$VERSION/fabric-installer-$VERSION.jar" fabric-installer.jar
# Install fabric, sign eula & remove installer
RUN java -jar fabric-installer.jar server -downloadMinecraft && \
rm fabric-installer.jar && \
echo "eula=true" > eula.txt
# Store the cache in an anonymous volume, which means it won't get stored in the other volumes
VOLUME /mc/config/cache
# Default value to keep users from eating up all ram accidentally
ENV XMS=4
WORKDIR /mc/config
# Source for flags:
# https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/
# Certain flags auto-scale if XMS is greater than 12 (see link for info)
ENTRYPOINT mv -n /mc/*.jar /mc/config && java \
-Xms"${XMS}G" \
-Xmx"${XMX:-$XMS}G" \
-XX:+UseG1GC \
-XX:+ParallelRefProcEnabled \
-XX:MaxGCPauseMillis=200 \
-XX:+UnlockExperimentalVMOptions \
-XX:+DisableExplicitGC \
-XX:+AlwaysPreTouch \
-XX:G1NewSizePercent="$([ $XMS -gt 12 ] && echo 40 || echo 30)" \
-XX:G1MaxNewSizePercent="$([ $XMS -gt 12 ] && echo 50 || echo 40)" \
-XX:G1HeapRegionSize="$([ $XMS -gt 12 ] && echo 16 || echo 8)"M \
-XX:G1ReservePercent="$([ $XMS -gt 12 ] && echo 15 || echo 20)" \
-XX:G1HeapWastePercent=5 \
-XX:G1MixedGCCountTarget=4 \
-XX:InitiatingHeapOccupancyPercent="$([ $XMS -gt 12 ] && echo 20 || echo 15)" \
-XX:G1MixedGCLiveThresholdPercent=90 \
-XX:G1RSetUpdatingPauseTimePercent=5 \
-XX:SurvivorRatio=32 \
-XX:+PerfDisableSharedMem \
-XX:MaxTenuringThreshold=1 \
-Dusing.aikars.flags=https://mcflags.emc.gs \
-Daikars.new.flags=true \
-jar fabric-server-launch.jar \
--universe /mc/worlds \
--nogui

81
fabric/README.md Normal file
View file

@ -0,0 +1,81 @@
# docker-mc-fabric
This repository helps you easily setup a modded Minecraft server using the
[Fabric mod loader](https://fabricmc.net/).
## Installing docker
You can follow the instructions
[here](https://docs.docker.com/engine/install/).
## Building the image
To build the image, you must specify the Fabric version using the `VERSION`
build argument. You can either do this using `docker`:
`docker build -t mc-fabric-server:latest --build-arg VERSION=0.6.1.51 .`
or using `docker-compose`, by specifying the argument in the
`docker-compose.yml` file and running:
`docker-compose build`
See the provided `docker-compose.yml` file for an example of how to specify the
build argument.
## Useful mount points
The container has three useful mount points:
* `/mc/config`: this is where all server config files reside.
* `/mc/config/mods`: this is where all mods should be placed.
* `/mc/worlds`: this is where the world files are stored.
I recommend mounting these to either a local directory or a volume, as to not
lose the server data.
## Environment variables
The container has two environment variables which can be set, namely `XMS` and
`XMX`. If `XMX` is not set, it will use `XMS`'s value by default. Note that
their value is expected to be an integer, which is then used as a quantity for
gigabytes. Therefore, only gigabyte precision is possible.
## Java flags
I use the Java flags defined
[here](https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/).
If you don't agree with this decision, you can change the `ENTRYPOINT` at the
end of the `Dockerfile` to the following:
```
ENTRYPOINT java \
-Xms"${XMS}G" \
-Xmx"${XMX:-$XMS}G" \
-jar fabric-server-launch.jar \
--universe /mc/worlds \
--nogui
```
This will only use the flags absolutely necessary, while still allowing you to
tweak the memory variables.
## Running the server
### docker
You can start the server with the following command:
```
docker run \
--rm \
--interactive \
--tty \
--publish '25565:25565' \
--detach \
mc-fabric-server:latest
```
Or, more compact:
`docker run --rm -dit -p '25565:25565' mc-fabric-server:latest`
This will start the server and run it in the background.
### docker-compose
If you prefer to use `docker-compose` (which I recommend), you can use the
provided `docker-compose.yml` file and edit it to suit your needs. By default,
it creates volumes for the three major mount points, and opens up port `25565`.
Then, you can start the server using `docker-compose up --detach` or
`docker-compose up -d`, because no one likes typing long commands.

22
fabric/docker-compose.yml Normal file
View file

@ -0,0 +1,22 @@
version: '3.5'
services:
fabric:
build:
context: .
args:
- 'VERSION=0.6.1.51'
image: 'mc-fabric-server:latest'
restart: 'unless-stopped'
stdin_open: true
tty: true
environment:
- XMS=4
- XMX=4
ports:
- '25565:25565'
volumes:
- '/data/config:/mc/config'
- '/data/mods:/mc/config/mods'
- '/data/worlds:/mc/worlds'