My oldest child recently got into Minecraft. While many of his peers play Bedrock Edition on an iPad or game console, my son plays the venerable Java Edition on an old computer. (And he launches it from the terminal! 🤓) To play together, I looked into running a Dockerized Minecraft server on my home server, and it was much easier than I expected.
Running a Dedicated Server
You can fire up the container with an individual
docker run command and/or daemonize it. But, I’ve been keeping it simple with
docker compose up in a byobu session.
Here’s my current docker-compose.yml file:
# docker-compose.yml version: "3.3" services: mc: image: itzg/minecraft-server ports: - 25565:25565 environment: EULA: "TRUE" SERVER_NAME: "Our Minecraft Server" MOTD: "First Peaceful World" DIFFICULTY: "peaceful" # https://github.com/itzg/docker-minecraft-server#memory-limit MEMORY: 2G # uncomment this to import a saved game. (put your savegame directory in the saves-to-import directory) # WORLD: "/worlds/My-World" volumes: - ./minecraft-data:/data - ./saves-to-import:/worlds:ro
There are a ton of available configuration options, but I’d like to highlight two things above:
- The game’s persistent data is written to a volume mounted to the host so we can easily access the files.
- The “WORLD” option is really handy for importing a save that was first created on another computer.
Connecting to the Server
After a few seconds, the server is ready to accept connections, but my clients don’t seem to see it for some reason. Minecraft will sit on the “Scanning for games on your local network” screen forever. No matter, you can “Add Server” to add it manually, and voila!
Most of my Minecraft knowledge is about a decade out of date. However, I’m aware that third-party tools can generate a web view of a Minecraft world similar to those in Google Maps. After searching around, it seems like Minecraft Overviewer is the prominent one these days.
docker run -e MINECRAFT_VERSION="1.17" -v `pwd`/minecraft-data/world:/home/minecraft/server/world:ro -v `pwd`/overviewer-data:/home/minecraft/render/:rw mide/minecraft-overviewer:latest
Given read-only access to the game data produced by the other container, and another volume to write to, this will produce a web map using Leaflet. The directory can then be symlinked into a web-served directory on the host like
~/public_html for access from any web browser.
It takes a few minutes to run, but the results are pretty spectacular:
Lastly, as is my wont, I threw a few shortcuts in a Makefile for easy access:
# Makefile start: sudo docker-compose up update: sudo docker pull itzg/minecraft-server sudo docker pull mide/minecraft-overviewer generate-map: time sudo docker run \ -e MINECRAFT_VERSION="1.17" \ -v `pwd`/minecraft-data/world:/home/minecraft/server/world:ro \ -v `pwd`/overviewer-data:/home/minecraft/render/:rw \ mide/minecraft-overviewer:latest
Reasons You Might Want to Build a Dockerized Minecraft Server
A DIY dedicated server is probably unnecessary for most people. If you’re just looking to play multiplayer locally and one of your machines is reasonably powerful, you can just “Open to LAN” from inside the game. If you’re looking to play with a larger group of folks outside your household, you’re probably better off with a paid hosted server. That could be either the official “Realms” or one of several third-party options.
But if you like to DIY, and you happen to already have a headless computer running 24/7 in your basement, then a Dockerized Minecraft server is pretty neat!