This guide shows how to host multiple Minecraft servers on a single machine with docker-compose.
mkdir minecraft_server
cd minecraft_server
mkdir data/
wget https://kylrth.com/post/minecraft/docker-compose.yml \
-O docker-compose.yml
This docker-compose setup uses itzg’s Docker image, which you see further documentation for here.
If you’re moving from a vanilla Minecraft world, do the following to get the different world directories in the right position:
cp -r ${OLD}/world data/server/world
mkdir data/server/world_{nether,the_end}
mv data/server/world/DIM-1 data/server/world_nether/DIM-1
mv data/server/world/DIM1 data/server/world_the_end/DIM1
Here’s the map from vanilla Minecraft directories to Spigot directories (which is what itzg’s container uses):
world/ -> world/
world/DIM-1 -> world_nether/DIM-1
/world/DIM1 -> world_the_end/DIM1
At this point go ahead and start it with docker-compose up
. When it first starts, it downloads the Minecraft implementation we specified with the TYPE
environment variable (in my case Paper).
If you want the server to run as a Systemd service, follow the instructions for enabling a docker-compose Systemd service here.
exposing two Minecraft servers on the same machine
In order to have two servers running, they’ll need to be listening on different ports. It’d be nice for users to not need to remember port numbers, but since Minecraft uses its own protocol over TCP a reverse proxy won’t help us. What we can do is create DNS A records for two subdomains that both point to the machine, and then these SRV records:
_minecraft
_tcp.minecraft1
0
5
25566
minecraft1.kylrth.com
_minecraft
_tcp.minecraft2
0
5
25567
minecraft2.kylrth.com
Once I’d done this, I had to wait like 30 minutes to start seeing the servers show up within the Minecraft client.
administration
Administration can be done with RCON by exec-ing into the container:
$ docker-compose exec minecraft rcon-cli
> whitelist add kylrth # add yourself to whitelist
Added kylrth to the whitelist
> op kylrth # make yourself op
> help # see other administration options here
...