Dockerizing a minecraft server
Friendship ended with pterodactyl, now portainer is my new friend
You might be aware that I run a modded minecraft server for myself and a few friends. At first I used docker and the cli directly, which was fine, but I did start to get sick of the complexities of always having to directly interact with a terminal to do anything. So I switched over to pterodactyl panel to manage the server, which worked well for a while, but ultimately still ended up not being optimal. At that point I switched back to using docker directly, but with the addition of portainer. Portainer is a web interface that allows for the easy deployment of containers and compose stacks. I did end up having to create some custom tooling, mainly a custom container image to handle server deployment
The Container
As you may already know, if you’ve read the prior article on my modded Minecraft infrastructure, (specifcally Section 2), I use packwiz manage the modpack on the server, and handle syncing to the client. This posed an issue with portainer as all the existing minecraft container images do not offer multi-loader/version support from the pack.toml file. So I made my own. It’s an image based on Alpine linux, with Java 21, GNU Nano, and itzg/rcon-cli pre-configured and installed. I’m also using itzg/mc-image-helper to handle minecraft and modloader installation. If you want to see this in more detail, check out the git repo
The Stack
Last time I tried to handle docker directly, I messed up the backups. Badly. This lead to data loss. So this time, I used (and actually tested) itzg/docker-mc-backup as a sidecar container to backup the named world data volume attached to the server container to a directory on the system. See the reference docker compose if you want to see exactly how this works.
Usage
Most use cases can be handled without touching a terminal. I can update the server, reset the container, or reset the world volume through the portainer web ui. The only time I need to open the container terminal is to add the first user to the whitelist and set them as an operator (with the rcon-cli command), or to manage files in the container (with normal linux terminal commands and nano).