How to Host a DIY Minecraft Server at Home with Docker
source link: https://spin.atomicobject.com/2021/07/21/host-minecraft-server-docker/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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
The official server distribution is a single Java jar, so it ought to be pretty simple to run. Before trying it, though, I searched for Docker images, and found a good one: itzg/minecraft-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!
Web Map
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.
As before, this toolās installation looks pretty straightforward, but I found a Docker image thatās even easier. This oneās a one-shot process (not a persistent service), so weāll use docker run
:
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 /var/www
or ~/public_html
for access from any web browser.
It takes a few minutes to run, but the results are pretty spectacular:
Makefile
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!
For more on self-hosting, check out posts from my colleagues Jordan and Matt.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK