Skip to content

Instantly share code, notes, and snippets.

@jaqque
Last active September 29, 2024 23:41
Show Gist options
  • Save jaqque/5f376a77099c84b07304f3d3da8db79d to your computer and use it in GitHub Desktop.
Save jaqque/5f376a77099c84b07304f3d3da8db79d to your computer and use it in GitHub Desktop.
Empire Minecraft Server Dockerfile / compose

EmpireCraft

Staring Docker

With Special Guest Compose

Building and running the EmpireCraft Minecraft Server

Building

docker compose build

or

docker build \
  --build-context source=https://github.com/starlis/empirecraft.git \
  --label com.docker.compose.project=empirecraft \
  --label com.docker.compose.service=empirecraft \
  --label com.docker.compose.version="$(docker compose version --short | sed 's/-.*//')" \
  -
  < Dockerfile

Running

  • docker compose up --detach will build (if needed) and start the server on 0.0.0.0:25565
  • docker container attach empirecraft-empirecraft-1 will attach to the console of the server
  • CTRL-c or stop will stop the server
  • Use CTRL-p CTRL-q to detach from the console and leave the server running

To launch the server, with the Compose volume, and attached to console:

  • docker run -it -v empirecraft_world:/world -p 25565:25565 empirecraft

Local EmpireCraft Repository

By default, the compose file will pull a context from Starlis' EmpireCraft GitHub repository.

If you add Dockerfile and compose.yaml to the EmpireCraft repository, you should remove the --from=source from the Dockerfile, and remove the additional_contexts from compose.yaml

---
name: empirecraft
services:
empirecraft:
build:
# remove the additional_contexts if you have a local copy of the repo
additional_contexts:
source: https://github.com/starlis/empirecraft.git
args:
world: ${world:-/world}
context: .
target: final
image: ${COMPOSE_PROJECT_NAME}
ports:
- 25565:25565
stdin_open: true
tty: true
volumes:
- world:${world:-/world}
volumes:
world:
### EmpireCraft https://github.com/starlis/empirecraft
### The server that runs Empire Minecraft
### A fork of Paper
## "Global" ARGs
ARG appdir=/app
ARG java_version=21
ARG suite=bookworm
ARG uid=1001
ARG user=emc
ARG world=/world
## BASE container
FROM docker.io/library/debian:${suite}-slim AS base
ARG appdir
ARG java_version
ARG suite
ARG uid
ARG user
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get upgrade \
--assume-yes \
--no-install-recommends \
--quiet \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install \
--assume-yes \
--no-install-recommends \
--quiet \
ca-certificates \
curl \
git \
gpg \
&& rm -rf /var/lib/apt/lists/*
# https://adoptium.net/installation/linux/
RUN curl -s https://packages.adoptium.net/artifactory/api/gpg/key/public \
| gpg --dearmor \
> /etc/apt/trusted.gpg.d/adoptium.gpg \
&& echo "deb https://packages.adoptium.net/artifactory/deb $suite main" \
> /etc/apt/sources.list.d/adoptium.list \
&& DEBIAN_FRONTEND=noninteractive \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install \
--assume-yes \
--no-install-recommends \
--quiet \
temurin-${java_version}-jdk \
&& rm -rf /var/lib/apt/lists/*
RUN adduser \
--disabled-password \
--gecos "" \
--home "${appdir}" \
--shell "/sbin/nologin" \
--uid "${uid}" \
"${user}"
## BUILD container
FROM base AS build
ARG appdir
ARG user
USER ${user}
WORKDIR ${appdir}
RUN git config --global user.name 'Gradle Build' \
&& git config --global user.email '[email protected]'
# remove the "--from=source" if you have a local copy of the repo
COPY --chown=${user}:${user} --from=source . .
RUN git submodule update --init --recursive
# for some reason, applyPatches fails if in the same RUN as cleanCache
RUN ./gradlew cleanCache --no-daemon
RUN ./gradlew applyPatches --no-daemon
RUN ./gradlew rebuildPatches --no-daemon
RUN ./gradlew createReobfBundlerJar --no-daemon
## FINAL container
FROM base AS final
ARG appdir
ARG user
ARG world
# 2GiB RAM
# https://docs.papermc.io/misc/tools/start-script-gen
ARG aikars_flags="-Xms2048M -Xmx2048M -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+ParallelRefProcEnabled -XX:+PerfDisableSharedMem -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1HeapRegionSize=8M -XX:G1HeapWastePercent=5 -XX:G1MaxNewSizePercent=40 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1NewSizePercent=30 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -XX:MaxGCPauseMillis=200 -XX:MaxTenuringThreshold=1 -XX:SurvivorRatio=32 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true"
USER ${user}
WORKDIR ${appdir}
COPY --from=build ${appdir}/build/libs/empirecraft-*.jar server.jar
WORKDIR ${world}
COPY --chown=${user}:${user} <<EULA eula.txt
eula=true
EULA
VOLUME ${world}
ENV AIKARS_FLAGS=${aikars_flags}
ENV APPDIR=${appdir}
CMD [ "/bin/sh", "-c", "exec /usr/bin/java ${AIKARS_FLAGS} -jar ${APPDIR}/server.jar nogui" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment