2 Commits
5 changed files with 54 additions and 24 deletions
+4
View File
@@ -1,3 +1,7 @@
## v0.2.0
- Migrate to custom RCON client: https://gitea.jovan04.com/evan/WiRCON
- Upgrade base image to Java 25
## v0.1.0 ## v0.1.0
- Initial release - Initial release
- Graceful shutdown via SIGTERM / SIGINT - Graceful shutdown via SIGTERM / SIGINT
+17 -13
View File
@@ -1,20 +1,24 @@
# extract mcrcon
FROM debian:bookworm-slim AS builder
ADD https://github.com/Tiiffi/mcrcon/releases/download/v0.7.2/mcrcon-0.7.2-linux-x86-64-static.zip /usr/bin/mcrcon.zip
RUN apt-get update && apt-get install -y unzip
RUN unzip -j /usr/bin/mcrcon.zip -d /usr/bin/mc-rcon && chmod a+x /usr/bin/mc-rcon/mcrcon
# actual image # actual image
FROM eclipse-temurin:21 FROM eclipse-temurin:25
RUN apt-get update
RUN apt-get install -y wget ca-certificates
RUN apt-get install -y git
RUN apt-get install -y python3
RUN apt-get install -y build-essential
RUN ln -s /usr/bin/python3 /usr/bin/python
# build the RCON client
RUN git clone https://gitea.jovan04.com/evan/WiRCON && cd WiRCON && make build && mv wircon.pyz /usr/bin/wircon.pyz && cp scripts/restart.py /usr/bin/restart.py
COPY --from=builder /usr/bin/mc-rcon /usr/bin/mc-rcon
COPY scripts/start-server.sh /usr/bin/start-server.sh COPY scripts/start-server.sh /usr/bin/start-server.sh
RUN chmod a+x /usr/bin/start-server.sh RUN chmod a+x /usr/bin/start-server.sh
COPY scripts/mcrcon /usr/bin/mcrcon
RUN chmod a+x /usr/bin/mcrcon COPY scripts/rcon /usr/bin/rcon
RUN chmod a+x /usr/bin/rcon
# default minecraft server files
COPY template/ /defaults/ COPY template/ /defaults/
WORKDIR /minecraft_data WORKDIR /minecraft_data
+29 -8
View File
@@ -16,7 +16,7 @@ git clone https://gitea.jovan04.com/evan/minecraft-docker && cd minecraft-docker
### Build the Image ### Build the Image
```sh ```sh
docker build -t minecraft_server . docker build --pull -t minecraft_server .
``` ```
### Run with Docker Compose ### Run with Docker Compose
@@ -36,7 +36,29 @@ On first startup (when the data volume is empty):
* A default RCON configuration is written * A default RCON configuration is written
* `server.jar` is downloaded from a provided link * `server.jar` is downloaded from a provided link
On subsequent startups, existing files are reused unchanged and environment variables are unused. On subsequent startups, existing files are reused unchanged and environment variables are unused. To reset the server or create a new one, change the name in `volumes: data: name: new_volume_name` in the `docker-compose.yml` file.
### Upgrading Java Version
Occasionally, Minecraft will update the Java version they compile their class files with. Because the Java runtime is pre-bundled with the Docker container, an update from Minecraft requires an update and rebuild of the Docker container.
You can tell this is required if there are errors like the following when trying to start the server:
```
minecraft_server | Error: LinkageError occurred while loading main class net.minecraft.bundler.Main
minecraft_server | java.lang.UnsupportedClassVersionError: net/minecraft/bundler/Main has been compiled by a more recent version of the Java Runtime (class file version 69.0), this version of the Java Runtime only recognizes class file versions up to 65.0
minecraft_server exited with code 1 (restarting)
```
To upgrade, change the base eclipse-temurin image's version to one supported by the latest Minecraft version. In `./Dockerfile`:
```
# previously, eclipse-temurin:21
FROM eclipse-temurin:25
```
Then, rebuild the container and start as normal:
```sh
docker build --pull -t minecraft_server .
docker compose up -d
```
### RCON Access ### RCON Access
Minecraft implements the Remote Console (RCON) protocol, which allows server administrators to remotely execute commands. See more info [here](https://minecraft.wiki/w/RCON) and [here](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol). RCON access is enabled automatically from inside the container only. **Do not expose the RCON service to the internet directly!!!** RCON is not encrypted, so exposing this service can give hackers direct access to your server's administrator console. Minecraft implements the Remote Console (RCON) protocol, which allows server administrators to remotely execute commands. See more info [here](https://minecraft.wiki/w/RCON) and [here](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol). RCON access is enabled automatically from inside the container only. **Do not expose the RCON service to the internet directly!!!** RCON is not encrypted, so exposing this service can give hackers direct access to your server's administrator console.
@@ -45,19 +67,18 @@ Log into the container:
```sh ```sh
docker exec -it minecraft_server bash docker exec -it minecraft_server bash
``` ```
Use the provided wrapper script (located at `/usr/bin/mcrcon`). The script dynamically reads the password from `/minecraft_data/server.properties`. Use the provided wrapper script (located at `/usr/bin/rcon`). The script dynamically reads the password from `/minecraft_data/server.properties`.
Send a single command: Send a single command:
```sh ```sh
mcrcon list rcon -e list
mcrcon stop
``` ```
For an interactive console (`Ctrl-C` or `Ctrl-D` to quit): For an interactive console (`Ctrl-D` to quit):
```sh ```sh
mcrcon rcon
``` ```
Use this the same as typing into the actual server console Use this the same as typing into the actual server console.
### Graceful Shutdown Behavior ### Graceful Shutdown Behavior
When the container receives SIGTERM or SIGINT: When the container receives SIGTERM or SIGINT:
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
exec /usr/bin/mc-rcon/mcrcon -p "$( exec /usr/bin/wircon.pyz -H localhost -p "$(
grep '^rcon.password=' /minecraft_data/server.properties | cut -d= -f2- grep '^rcon.password=' /minecraft_data/server.properties | cut -d= -f2-
)" "$@" )" "$@"
+3 -2
View File
@@ -7,7 +7,7 @@ if ! test -f /minecraft_data/server.jar; then
echo "ERROR: SERVER_JAR_DOWNLOAD_URL not set for initial volume creation" echo "ERROR: SERVER_JAR_DOWNLOAD_URL not set for initial volume creation"
exit 1 exit 1
fi fi
wget -O /minecraft_data/server.jar "${SERVER_JAR_DOWNLOAD_URL}" wget --no-verbose -O /minecraft_data/server.jar "${SERVER_JAR_DOWNLOAD_URL}"
fi fi
# server.properties # server.properties
@@ -24,12 +24,13 @@ if ! test -f /minecraft_data/eula.txt; then
cp /defaults/eula.txt /minecraft_data/eula.txt cp /defaults/eula.txt /minecraft_data/eula.txt
fi fi
export MCRCON_PASS=$(grep "^rcon.password=" /minecraft_data/server.properties | cut -d '=' -f 2- | head -n 1) export MCRCON_PASS=$(grep "^rcon.password=" /minecraft_data/server.properties | cut -d '=' -f 2- | head -n 1)
# shutdown process # shutdown process
function shutdown { function shutdown {
echo "stopping Minecraft server..." echo "stopping Minecraft server..."
/usr/bin/mc-rcon/mcrcon -p ${MCRCON_PASS} -w 5 "say Server is restarting!" save-all stop /usr/bin/wircon.pyz -H localhost -p ${MCRCON_PASS} -E /usr/bin/restart.py
wait $SERVER_PID wait $SERVER_PID
} }