By Akira Wong, Intern from UC Irvine and Proud Heng, Intern from UC San Diego

We learned a ton about how containers impact operating applications over this past summer with the {code} team. Before we began this “Summer of {code},” we needed a goal. We wanted a way to challenge ourselves and it was important that we find a project that was relevant to us and provided opportunities to explore containers, open source and what it means to be a part of the {code} team. After doing some research we came up with our research question:

What would it take to run Minecraft in a container?

Building blocks, adventure, and a playground in one game – Chances are you or someone you know plays Minecraft. To properly grasp this phenomenon check out this short video featured by WIRED.

If you have ever looked into the technical aspects of actually running a Minecraft server, you’ve probably noticed that it is notoriously tedious and even difficult to set up at times. After all, there are numerous hurdles to overcome – to deploy a server one must configure dependencies, open ports, and accept Minecraft’s end user license agreement. While this may seem trivial to some, by the time the rest of us figure out how to maintain and upgrade the server, our friends might have already moved on!

Basically setting up and maintaining a Minecraft server is tough. Players just want to play with their friends and family.

So why not make it an easier process in the long run with containers and persistent storage!

Docker to the rescue!

Docker is a rising star in infrastructure management technology. It’s a tool that allows you to easily deploying applications. We’ll be using what Docker calls containers to run our Minecraft Server. Containers let us create a bundle of everything that’s needed to skip the tedious setup and instead focus on an easy deployment of applications such as Minecraft servers. In addition, containers can be run nearly anywhere – on your laptop, your home server, in a virtual machine or using cloud hosting such as Amazon’s EC2 cloud. Even if you don’t understand the technical details, it’s time to get excited. This means that not only can we deploy a Minecraft server in less than fifteen minutes, it can also stay online forever. If we hand off the configuration to Docker and the hosting to cloud environments, then we have more time to focus on what we actually care about – playing Minecraft.

However, there’s one tiny problem there’s always a hiccup

In exchange for portability and automatic deployment, Docker enforces “statelessness”. This means that a container is meant to live, perform its service, and die.  Ultimately, there is no difference between individual container instances. This poses a major problem to our prospective server – persistence. If data created by our server will be deleted as soon as the container stops running this questions the sustainability of our Minecraft server.

If you’ve been following along, maybe you already see the looming problem, but for those who don’t quite grasp it…

Imagine you’ve already set up your Minecraft server in a container- it was a breeze, after reading and sharing this blog, you made an AWS account and got a Minecraft server online quickly. Things have been going great. Two weeks have passed, and you and the other players have assembled a castle, built a farm, and established friendly relations with the local villagers. However, you’ve had a nagging feeling in the back of your head lately. What was that thing about containers being stateless? Would our Minecraft server world data be persistent even if our container was killed? What would happen to all our work if this container ever shut down?

As soon as this thought occurs to you, disaster strikes! A janitor trips over a cord, there’s a combination hurricane, tsunami, earthquake, zombie apocalypse and all of AWS goes down. Darkness. Days go by and eventually AWS comes back online. You hesitantly restart the container, trembling as you log in. Only to find…

Everything is gone.

  • That castle? Disappeared.
  • Your watermelons? Never to be eaten.
  • That villager you named Villager McVillageface? You’ll never see him again.

All you can see is the empty expanse of a plains biome. Your players burst into tears when you break the news and you struggle to hold it together yourself. If only this disaster could have been averted. If only there were some way to achieve persistence in containers – then the world may have been saved.

As it turns out there is a way to save state in containers. Using what Docker calls volume mounts it is possible to mount local storage into the container. Then, upon restarting a container with the same volume mount, the data will still be there. However, note that this applies only to local storage, if the container host goes up in flames or you ever want to upgrade it it, then you will need to jump through more hoops.

Fortunately, we can use REX-Ray to circumvent these issues and connect to remote cloud storage volumes. REX-Ray is an open source project from {code} that allows us to future-proof our Minecraft server. By storing the data remotely, we don’t have to worry if our container or even the whole server is lost while also laying the groundwork to be able to quickly upgrade our server. REX-Ray handles the details of creating storage volumes and connecting one to our Minecraft server container. Using Docker’s volume mounts and REX-Ray we can save our Minecraft world data so there’s no longer need to worry about data being lost forever…

Sound good? Hop over to our GitHub project for detailed instructions and you’ll be up and running in no time.