Cheap Minecraft Server in AWS with Docker and Traefik

minecraft-like figure on the grass

According to the Minecraft Realms plan pricing page, you can get a realms server at around £5.59 per month. You get some nice conveniences there but… I refuse to pay much at all when I can throw some infrastructure together myself in the cloud to create the ultimate cheap Minecraft server.

Considering my Docker instance running Traefik hosts another 3 or 4 of my personal services along with a Minecraft server, then this solution only costs me around £1.50 a month.

I chose to go with a single AWS EC2 instance that runs Docker. Minecraft runs in a container and sits alongside other personal websites and services that I host there too.

I use Traefik to route traffic coming in to this single host for various TCP ports as well as HTTP(s) on different hostnames. This essentially levels up the cost savings even further as I don’t need multiple EC2 instances (one for each service), and I don’t even need to pay for something like an application or network load balancer, as Traefik does this for me.

A Quick Review of Alternatives

There are other alternatives to consider if you’re looking for a cheap Minecraft server, so don’t take this as being the only option. Here is what I’ve used in the past before settling on my current solution:

  • Minecraft on a dedicated cloud VM. If you just want a dedicated Minecraft VM in the cloud, then DigitalOcean is a good, cheap option. You can also get fairly cheap instances Vultr.
  • Running Minecraft on my own personal Raspberry Pi Kubernetes Cluster. I was even able to expose it over the internet for friends to play on by leveraging a Pi device as a dedicated router. I then used port forwarding to get it working through my double NAT setup. The ARM container was a little slow as a server for more than 2 or 3 players on Raspberry Pi hardware though.
  • Minecraft Server on a home PC / Workstation, with port forwarding to allow other players to connect. This is not ideal, especially on Windows machines or systems that you don’t want to leave running 24/7 as you would for a dedicated server.
  • Various other Minecraft-as-a-service providers. These are decent options in some cases. However for me price and control are important, and I much prefer to self host in this case.

Cheap Minecraft Server in AWS EC2 with Traefik

I used my Cheap Traefik EC2 Docker Hosting solution as the base. You can read that article to get access to the CDK resources required to deploy it yourself.

The cost benefits to using this particular recipe are:

  • EC2 Graviton2 ARM based processor – slightly cheaper to run than Intel and AMD. The downside is more limited software choices. You need to make sure you use ARM compatible packages or Docker images.
  • Spot instance – this has massive savings over a normal lifecycle EC2 instance. The downside is that it can be terminated at any time with only a couple of minutes of notice. When using these you need to make sure you have good data persistence that is not local to the EC2 instance. I personally use a mounted EFS volume. It is re-attached to a new instance from the autoscaling group if the old instance is terminated.

If you don’t use the CDK solution I mentioned above, then alternatively deploy yourself an EC2 instance. Give it an elastic IP address, set up the Security Group ingress rules accordingly, and get shell access. First thing you’ll want to install is Docker, then you’re pretty much good to go.

Minecraft Docker Image

I found a great Minecraft Docker image that is well maintained and has the correct ARM image builds for use on Graviton2 hardware. Check out itzg/minecraft-server. There are other arch builds there that’ll run on just about any other platform.

Docker Compose Service

If you use docker-compose, then here is the simple service definition to get things running.

version: "3"

networks:
  web:
    external: true
  internal:
    external: false

services:
  mc:
    image: itzg/minecraft-server:2021.1.0-multiarch-latest
    environment:
      EULA: "TRUE"
      VERSION: "1.16.5"
      ENABLE_AUTOPAUSE: "TRUE"
      OVERRIDE_SERVER_PROPERTIES: "TRUE"
      MAX_TICK_TIME: "-1"
      TYPE: "BUKKIT"
    labels:
      - traefik.tcp.routers.mc.rule=HostSNI(`*`)
      - traefik.port=25565
    networks:
      - web
    volumes:
      - /data/mc:/data

The docker-compose definition will run a Docker container using the latest multiarch image (which will run on ARM devices). When starting, the container will prepare and run a Minecraft 1.16.5 server. It will also use Bukkit and enable auto pause. The game server does not tick over when there are no players connected.

Traefik Configuration

In the docker-compose definition above, you might have noticed the container labels. The labels prefixed with traefik are used to inform Traefik of how to route network traffic.

the cheap minecraft server uses a Traefik TCP router with HostSNI *
The TCP router using HostSNI on *

In our case, TCP connections are required on port 25565 and HostSNI is used to route those coming in for * (all hosts). The TCP connections on port 25565 go to Traefik, and based on this rule, directed to the Minecraft container.

There is one limitation to be aware of here, and that is that you can only use HostSNI with * for connections that do not use TLS. This is because Server Name Indication (SNI) is an extension of the TLS protocol.

I don’t believe Minecraft supports TLS in any case though. It just means that you won’t be able to have more than one Minecraft server container using the same port running on the single Docker host.

Finishing Off Configuration

Lastly, you might want to point a convenient Host record (A record) to your AWS EC2 Elastic IP address. For example: yourmcserver.example.com -> 1.2.3.4.

All being well, you should now be able to find and connect to your server.

minecraft server listing

Cosmosis (iOS) – updated to version 1.3

So heres an update that is slightly off my usual subject matter! I have been spending a little bit of time updating my 2D Space shmup game I have developed for iOS (iPhone, iPod touch, iPad). I  finished submitting the update to Apple on 04/08/2011, and this morning I saw it has now been approved, so it is ready to be downloaded / updated from the App Store.

 

Bonus level 2 added in version 1.3

 

Here is a list of the most significant new features in version 1.3.

 

– Unlocked all levels by default
– New (Second) Bonus Level added
– New enemy ship type added
– New enemy ship attack patterns (more challenging/interesting)
– New scrolling level select screen
– Main menu redesigned and new ambient music added for menu and in game
– OpenFeint updated
– New News menu option added for the latest news and announcements
– Game difficulty tweaked to make it slightly more challenging
– Bosses are a bit to tougher to fight now
– Survival mode difficulty tweaked
– New loading & credits screen
– App rating dialog that appears after a few days now works

 

So there is some new content as well as better difficulty and more challenging enemies to fight. I also added an interesting new feature – the News screen. This integrates with OpenFeint and pulls down and news / announcements I make on my developer control panel for OpenFeint into this custom designed (Cosmosis themed) News screen. It also updates the App’s badge icon according to the number of new (unread) news announcements and displays a small badge icon on the news menu in game. The main reason I developed this extra bit, is that I would like to be able to notify users of any future new releases (apps) I may release.

 

If you have any feedback or comments about Cosmosis, feel free to leave them below, or grab a copy and leave me a review on iTunes!

My first iOS game released on the App Store – Cosmosis

So I finally got my first game (and app) released on the App Store the other day. It is a 2D Space shooter called Cosmosis. Here is a feature / gameplay video and a link to the official App Store page. Check it out if you are into iOS games. It is compatible with the iPhone, iPod Touch and iPad!

The Official Game Page

httpv://www.youtube.com/watch?v=pnJCuaCOJzo

Here are a couple of screenshots:

Cosmosis - Gameplay screenshot

Cosmosis - Gameplay screenshot 2

http://itunes.apple.com/us/app/cosmosis/id404662019?mt=8

My workspace and hardware zen

Everyone has their own relax or zen area where they like to spend time getting away from reality and de-stressing. One of mine just happens to be the same place where I get a lot of work done – my main gaming platform and home office area! Since we moved into our new flat, I found that there wasn’t much space to set up my PC. Last weekend I whipped out the old jigsaw and sliced a couple of inches off the side of my PC desk in order to get it to fit into this corner.

I then decided to neaten up and organise everything a bit to enhance my working conditions when I do work from home. I made a “ghetto” iPhone dock out of the packaging the phone came in, using the plastic dish the phone is cradled in. I cut out a small area at the bottom for the iPhone connector to fit in, then routed the cabling into the box itself, which sits diagonally in the lid of the box, flipped upside down. The cable then comes out the back and plugs in to the power socket behind my desk. This keeps the cabling nice and neat and I just plonk the phone down into the dock when I get home for a charge. I don’t need a USB connection to the PC as I have SSH enabled via a jailbreak – I therefore use Wifi access and WinSCP or SCP from Putty to transfer files between PC and phone.

Behind this is my touch sensitive desk lamp, in front of the dock is my work IP phone which connects up to our VOIP server. Then we have my main PC which consists of the following: Asus P45 P5Q motherboard, E8400 3.0GHz Core2Duo CPU overclocked to 3.6GHz in Summer and 4.0GHz in Winter. 4GB OCZ DDR800 RAM running at DDR1000 speeds and an ATI HD 4870 graphics card which has a custom flashed bios which overvolts the GPU and applies a generous overclock. I used to have a nice quiet watercooling loop in the PC, but sold it recently and went back to air cooling. I plan on doing another Watercooling build soon and will hopefully post the process and worklog here when I do. The other peripherals consist of a Dell 24″ LCD (1920×1200), G15 Keyboard and Logitech MX518 mouse.

I use this PC for just about everything – all my PC gaming, Web browsing, a little bit of programming and Virtualisation (On top of Windows 7 Professional it is running VMWare Server 2.0) with a variety of guest VMs that I use for testing and practising various Windows and Linux server technologies.

Other hardware I have lying around is an old Dell Poweredge 2U server which I run VMWare ESX 3.5 and a Dell Optiplex machine running uBuntu 8.04, with VMWare Server 2.0 for linux and a guest VM operating system running on top of that which runs uBuntu Server 9.04 and this very website.

Anyway here are a few photos of my nice clean new workspace.