Host a Minecraft server with Docker

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.