Free and Fantastic: My Zero-Cost Oracle Cloud Minecraft Server with Docker

Playing Minecraft has become a recurring part of my year – what my friends and I affectionately call the “Minecraft Fever.” However, an issue we constantly faced was the expense of renting a server at $15 per month. We’d play for about 5-10 days, and then, as the fever waned, we found ourselves still paying for the server for an additional 2 months with no one logging on. The cycle repeated every time the Minecraft fever rekindled.

Frustrated by this costly pattern, I experimented with Amazon Lightsail, following an article on setting up a Minecraft server. While the costs averaged around $10 per month and offered better performance than typical hosting services, the expense still felt burdensome.

Determined to minimize costs, I took the plunge and created a Minecraft Server on my home network. This turned out to be a nearly cost-free solution, with the only expenditure being electricity. Fortunately, I had spare hardware, eliminating any upfront costs. Although it worked well for a while, I grappled with the unease of exposing my home network to the internet.

Discovering the Cost-Free Solution

In the latter part of the previous year, my quest for a budget-friendly Minecraft server led me to an unexpected solution – Oracle Cloud’s remarkably generous free tier. With their ARM VM instances, you’re entitled to the first 3,000 OCPU hours and 18,000 GB hours monthly, all at no cost. To put it into perspective, this translates to 4 OCPUs and 24 GB of memory! You have the flexibility to allocate this power to a single VM or distribute it across up to 4 VMs (1 OCPU / 8 GB each).

In an era where support for ARM processors is not widespread among programs, the beauty of the Java Programming language shines through. Java’s versatility enables its programs to run seamlessly on all processors. This aligns perfectly with the ARM VM, making the Java version of Minecraft an ideal match for this cost-free solution.

Setting Up the ARM VM

Having successfully created an Oracle Cloud account, I navigated to the “Instances” page to embark on the process.

Upon selecting “Create instance,” I began by assigning a name to my instance. The Image was set to “Canonical Ubuntu 22.04,” and for the shape, I opted for “VM.Standard.A1.Flex.” While I personally went with 2 OCPUs and 12GB memory, you have the flexibility to scale up to 4 OCPUs and 24 GB of memory – the choice depends on your specific needs. I reserved the rest for other VMs.

Next, for the virtual network interface card, I established a new virtual cloud network titled “minecraft-paper-docker-vcn” and a corresponding subnet named “minecraft-paper-docker-subnet.” I left the other settings unchanged for simplicity.

I proceeded to download my private SSH key, facilitating terminal access through PuTTY.

Finally, concerning the boot volume, I stuck with the default settings, granting me a spacious 46GB of disk space.

You may notice an apparent monthly cost of two dollars, but rest assured, I’ve yet to encounter any charges personally – a significant improvement over the previous $15 monthly expense.

However, during the setup, I encountered a minor hiccup with an error message: “Out of capacity for shape VM.Standard.A1.Flex in availability domain AD-2.” A swift solution was found by switching the placement to AD1. You may need to perform a similar adjustment based on your circumstances.

Connecting to My VM Using PuTTY

If you’ve made it this far, congrats! You should be looking at a screen that provides all the essential details.

Armed with my IPv4 address, private key, and username, I’m ready to connect. The next step involves installing PuTTY and PuTTYgen on my system.

PuTTY serves as my gateway to the VM, while PuTTYgen is crucial for converting my private key into a format compatible with PuTTY.

To get both tools installed, I downloaded the installer from this link Download PuTTY: latest release (0.80) (greenend.org.uk). I opted for “putty-64bit-0.80-installer.msi” since I use a 64-bit x86 processor. You’ll likely need the same version.

After installation, I launched PuTTYgen and loaded my private key. I had to choose “All Files” to locate my key wherever I downloaded it.

I saved the private key again – it’s now ready for use with PuTTY.

Now, I open PuTTY, enter my IPv4 address, and navigate to Connection/Data.

I input my username under “Auto-Login username,” then proceed to Connection/SSH/Auth/Credentials.

I load my PuTTYgen private key then go back to the Session.

Then enter a saved session name, click Save, and then Open. This way, I can reload the session later.

Upon connection, I encounter a popup – I simply press Accept, and I’m in!

In the terminal, I type the following commands:

Bash
sudo apt-get update && sudo apt-get upgrade

Here’s a breakdown:

  • “sudo” signifies “using admin power.”
  • “apt-get” manages software packages.
  • “apt-get update” fetches the latest updates.
  • “apt-get upgrade” applies the updates.
  • “&&” allows me to execute two commands simultaneously.

When prompted to continue, I type “Y.” If there’s a prompt to restart services, I just press Enter.

Once these commands finish, my VM is up-to-date. I consider running these commands monthly to ensure my system runs smoothly.

Installing Docker and Docker-Compose on My VM

Now, let’s get Docker and Docker-Compose up and running on my VM. Docker allows me to run software in my VM, essentially creating mini VMs called containers. In my case, I’ll be running Minecraft in one of these containers.

Docker-Compose comes into play to make Docker more user-friendly – a boon for someone like me who’s not an expert.

Let’s start entering the commands:

  1. Adding the Docker Repository Key to apt:
Bash
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  1. Installing all of Docker’s dependencies:
Bash
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
  1. Installing Docker itself:
Bash
sudo apt install -y docker-ce
  1. To confirm the successful installation, I check for “active (running)” in green using:
Bash
sudo systemctl status docker
  1. I exit out using “Ctrl” + “C.”
  2. Downloading Docker-Compose:
Bash
sudo curl -L https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
  1. Making the program runnable:
Bash
sudo chmod +x /usr/local/bin/docker-compose
  1. Checking if I installed it successfully:
Bash
docker-compose --version

If successful, it should display a version number.

Docker and Docker-Compose are now successfully installed on my VM.

Running Minecraft in Docker on My VM

Now, let’s get Minecraft up and running in Docker on my VM. I’m currently in the directory /home/ubuntu. To confirm my current directory, I use the command:

Bash
pwd

If I’m not there, I can navigate using:

Bash
cd /home/ubuntu

Now, let’s create a directory for the server and navigate into it:

Bash
 mkdir mc
Bash
 cd mc/

Next, I’ll create a file called “docker-compose.yaml,” which acts as a blueprint for Docker. This blueprint will construct the Minecraft Server. I’ll use nano, a text editor for the terminal. I’ll run this command:

Bash
nano docker-compose.yaml

My screen should resemble this:

Now, I’ll copy the following YAML configuration:

YAML
version: "1.0"
services:
  minecraft:
    image: "marctv/minecraft-papermc-server:latest"
    restart: always
    container_name: "mcserver"
    environment:
      MEMORYSIZE: "8G"
      PAPERMC_FLAGS: ""
    volumes:
      - "/home/ubuntu/mc/volume:/data:rw"
    ports:
      - "25565:25565"
    stdin_open: true
    tty: true

To paste into Nano, I’ll right-click.

A few things to note:

  • Pay attention to the “image” field. If I want to change the Minecraft version or type, I’ll update the image. I can find different images here. I’m using Paper for a performance boost in vanilla gameplay, but if I want to play modded Minecraft, there are likely Docker images available for me on this site.
  • The “MEMORYSIZE” should be about 70% of my VM’s RAM to ensure smooth operation.
  • The “volumes” setting is where the container’s “disk space” is set up. “:/data:rw” means the container has read and write access to this location.

Now, I’ll save and close Nano:

Press “Ctrl” + “S” to save

Press “Ctrl” + “X” to close

To confirm success, I’ll use this command:

Bash
cat docker-compose.yaml

This should print out what I wrote in Nano.

Now, let’s start the party and test run our Minecraft server:

Bash
sudo docker-compose up

This command reads the blueprint and builds the Minecraft server.

Now that Minecraft has booted up correctly, I’ll press “Ctrl” + “C” to close it.

Dealing with Firewalls

Now, I need to open up three layers of the firewall so that my players can connect to the server.

The first layer was already handled by our blueprint.

The next layer is our VM firewall. I’ll use this command:

Bash
sudo iptables -A INPUT -p tcp --dport 25565 -j ACCEPT

Now, I need to open the Oracle Subnet firewall, which is done on the site.

I’ll navigate back to Instances | Oracle Cloud Infrastructure and open my VM.

Then, I’ll click on my Virtual Cloud Network for the VM. I called mine “minecraft-paper-docker-vcn.”

In there, I’ll click on my subnet. I called mine “minecraft-paper-docker-subnet.”

Now, let’s click on the only security list there. Mine was called “Default Security List for minecraft-paper-docker-vcn.”

Click “Add Ingress Rules.”

Set “Source CIDR” to “0.0.0.0/0”, “Destination Port Range” to “25565.” and “IP Protocol” to “UDP.”

Press “Add Ingress Rules.”

Now, I’ll repeat the process, but this time, in addition to setting “Source CIDR” and “Destination Port Range,” but I’ll set “IP Protocol” to “TCP.”

Now, I’ve successfully opened port 25565 on TCP and UDP in the Oracle Subnet.

Testing the Minecraft Server with My Player

Now, let’s test run my server once more, but this time, I’ll try to join the server as a player. I’ll remember to run this command again:

Bash
sudo docker-compose up

I use my VM’s public IPv4 address in Minecraft

I did it! I could technically start sharing my IP with my friends and start playing now. However, there is one more thing to save me some grief. The server is only up as long as my terminal is up.

To fix that, I want to add “-d” to my start command:

Bash
sudo docker-compose up -d

This still boots the server but runs it in the background.

If I want to check if my server is running, I could use this command:

Bash
sudo docker-compose ls

Wrapping Up My Minecraft Server Journey

Hooray! I’ve successfully set up my Minecraft server on Oracle Cloud using Docker! By following these steps, I’ve not only made it cost-effective but also optimized the performance for an awesome gaming experience with my friends.

With Docker and Oracle Cloud, I’ve created a server setup that’s flexible, scalable, and easy to modify. Whether it’s tweaking configurations or expanding the server for more players, I have the power at my fingertips.

As I dive into the Minecraft adventures, I can explore additional Docker features and fine-tune my server further. Staying updated with the latest releases ensures I’m always in sync with the best enhancements.

Should I encounter any challenges or have questions, the Minecraft and Docker communities are there to lend a helping hand. Time to embark on exciting journeys in the blocky world—happy gaming!