Want to be a hero to your kids this Christmas? Want your nerdyism to make you the coolest mom or dad in the neighborhood? What you neighbors thank you for providing a safe online environment for their kids to play minecraft?

Let’s run a minecraft server using Docker in 5 minutes or less.

Assumptions

This article assumes you have the following:

  • The ability to stand up a CoreOs host in your favorite cloud
  • The ability to work at a Linux command line

It will help if you have:

  • Some familiarity with Docker
  • Some familiarity with SystemD

The article is inverted. You will have the thing up and running, then we will dive in to the why and how of it.

This is all based on my Minecraft repository.

Be a Christmas Hero

I recommend a server with 2GB of memory.

Set up a container just for the data.

docker run \
  --detach \
  --name minecraft-data \
  --volume /minecraft/WORLD  
  behemphi/docker-minecraft:1.8.6

Stop this container, it need not be running and it is only taking up valuable memory resources.

docker stop mc-data-only

Run the Minecraft server.

docker run \
  --detach \
  --env MOTD="My name is Dad and I am all-powerful." \
  --publish 25565:25565 \
  --volumes-from minecraft-data \
  behemphi/docker-minecraft:1.8.6

Go to the Dinnerbone site and check to see that the server is up.

Go play with your kids, you can read the rest of this later.

Don’t be a Christmas Zero

There are some pitfalls to avoid and some extra benefits you can take advantage of to avoid be a WORLD-killing parent.

Memory

For all that Minecraft is an amazingly well written game, it is still Java. Java likes memory. You will need a 2GB machine. This generally will support the 6 or 7 kids I see on it at any given time.

Dedicated Data Container

Yes, you can skip the percieved complexity of a dedicated data container. I did, and I regret it because I kept loosing game state on system failures.

If you do not separate the data from the running server, certain headaches ensue on a restart or when you want to upgrade. These will generally result in a loss of data.

Auto Restarts

CoreOs will restart on you. This is a good thing as it is auto-updating.

To ensure the server comes back up immediately following a system reboot, place the relevant unit files in the directory /etc/systemd/system

Run a Creative World

Kids like to play in “creative mode” to build fantastical elements in the game. The great thing about a containerized server is that you need only start a new container in creative mode. This is in lieu of becoming an expert in running a Minecraft server in various modes.

Start the dedicated data container:

docker run \
  --detach \
  --name minecraft-creative-data \
  --volume /minecraft/WORLD  
  behemphi/docker-minecraft:1.8.6

Stop it and start the server container:

docker run \
  --detach \
  -env GAMEMODE=1 \
  -env FORCE_GAMEMODE=true \
  --env MOTD="My name is Dad and I am all-creative." \
  --publish 22334:25565 \
  --volumes-from minecraft-creative-data \
  behemphi/docker-minecraft:1.8.6

So, when you kid wants to connect to the creative server, they will need to specify the port as well. They are used to this.

General Server Settings

If you look at the Dockerfile, you will see that there are a number of settings exposed as environment variables. These represent sane defaults. If you would like to learn a bit more about how to run a server, you can find more informaiton on each setting here.

The creative world section above is an example of how ot use these settings to accomplish a goal.

Managing Lists

The server comes with the capability to blacklist players you do not want to be able to join the server. Conversely it also has a whitelist for allowing only those players on. This is a great feature for a parent who wants to allow only players who are known to them and/or their child to play.

What I have yet to find though is a good way to manage this file. It is dynamic data so it cannot be part of the server image. Further, it is data generated by a person outside the game.

I am thinking about building another dedicated data container with a small application that allows me to edit the files on the fly. Another thought would be to used confd in some clever way.

Server logs

A great side effect of running a server is that you have the server logs. This means when that neighbor kid drops multiple f-bombs or menaces others in the game, you have a written record:

ME: Johnny was threatening my son and using foul language PARENT: Johnny would never do that, he doesn’t even know those words ME: This is a log from their game last night PARENT: … PARENT: Oh, oh my … I will have a talk with him ME: Thanks, and please let him know he is banned for the next two weeks.

Welcome to Heroism Docker Style

So the real point of this for me was to figure out what it would take to intelligently run a legacy application in Docker. If you are interested in the engineering aspects of this effort, you can check out the original blog post I wrote for StackEngine.

You can also find a some information on how to run the latest snapshot and backup your data in the README

Happy Holidays.