Minecraft Server with Linux and Docker

In todays blog, I will go through a step by step process on how I managed to deploy a Minecraft server using Linux server and docker.

This little project started when my friends wanted to play Minecraft together. We could very well play using the Minecraft: Bedrock edition but it had a blaring limitation. Although it is very easy to create a world and join friends by adding them, the main limitation was the uptime for that instance. If the host of the world leaves the game, everyone who was presently connected to that session will get disconnected. We were forced to deal with this for a few days until I considered paying for a server. Mojang offers a service called Minecraft Realms. This is a subscription based service where Mojang will host the Minecraft Server for you. I thought about paying but ultimately decided on self hosting a server using a spare machine. I did some research and decided to go with Minecraft: Java edition on Linux server and docker.

Downloading ubuntu server and flashing removable media

The first step I took were to do some light maintenance on the desktop by cleaning the dust and installing a spare hard drive for the OS. I then navigated to Ubuntu’s webpage to download a copy of Ubuntu Server 22.04.1. I then flashed the Ubuntu image onto a flash drive using an application called Rufus. The steps are as followed

  • Download Ubuntu by selecting Download Ubuntu Server 22.04.1 LTS
  • Head over to Rufus and select Rufus 3.21 (1.3 MB)
  • Launch the executable for Rufus and accept any UAC prompts
  • Plug in your flash drive and select it via Device
  • Under Boot selection select the option Disk or ISO image and then click on SELECT
  • File explorer should launch. Locate the Ubuntu image ubuntu-22.04.1-live-server-amd64 in your downloads folder and select Open
  • Select the option Start at the bottom and you should have ISOHybrid image detected
  • Select Write in ISO Image mode (recommended) and then OK
  • Accept the prompt to delete all of the date on the flash drive and wait for the drive to finish flashing
  • Eject your flash drive when done via the taskbar > Show hidden icons > Hardware and media eject > Right Click > Eject Flash drive

Installing Ubuntu

Now that the removable media has been flashed with the ubuntu image, I turned on my machine and let it boot via the newly connected flash drive. The guide for installing ubuntu server can be found on their official page. The steps should be as followed.

  • Select your preferred language from the available list
    • Select a keyboard associated with your preferred language
  • Select the Install Ubuntu option
  • Under network connections, Ubuntu should automatically assign an IPv4 address to you via DHCP (Example: 192.168.0.20). Write down that IPv4 address for later use
    • Skip the option proxy address by selecting Done
    • Skip the option mirror address by selecting Done
  • Under Guided storage configuration, select your hard disk
    • You may select either Use an entire disk, Set up this disk as an LVM group, or Custom storage layout
    • For the easiest configuration, select Use an entire disk and then select Done
  • Under Storage configuration, verify the options selected and hit Done
    • Select Continue on the Confirm destructive action prompt
  • Under Profile setup you will create a name, server name, username, and password
  • Under SSH Setup, be sure to select the option Install OpenSSH server and then select Done
  • Under Featured Server Snaps, be sure to select docker canonical Docker container runtime and hit Done
  • Let the installation process and select the option Reboot Now once under Install complete!
    • Remove your flash drive once prompted

SSH into the server and check for updates

Now that Ubuntu has been installed, I remoted into the new server from a Windows Machine. I have PuTTy installed but these steps can be followed via Windows PowerShell.

  • Launch Windows PowerShell and type the command ssh <username>@<your server’s ip address>
  • Run the command sudo apt-get update and then enter your password
    • This will check for new software
  • Run the command sudo apt-get upgrade
    • This will update the software on your machine
    • Type Y when prompted Do you want to continue?
  • Check if docker is installed properly by running docker –version
    • Your results should come out as Docker version 20.10.17, build 100c70180f
      • May differ depending on your version of docker
Replace the red edit with your server IP address (ex: 192.168.0.20)

Add your user to the docker group

In order to avoid having to type sudo when using any docker commands, I added my user to the docker group. An example of the output for typing a docker command with no permissions will result in Got permission denied while trying to connect to the docker daemon socket. The following steps will ensure that I have provisioned the necessary permissions to my user account.

  • Type sudo groupadd docker
    • This will create a group called docker
  • Type sudo gpasswd -a <your username> docker
    • Example: sudo gpasswd -a homelab docker
    • Result should be Adding user <username> to group docker
    • This will add the user to the newly created group “docker”
  • Restart your server for changes to take effect by either power cycling the server or typing sudo reboot
  • Test your group access by typing docker ps
    • This will show you if you have any running containers. It should be empty upon a fresh install of Linux/docker

Installing the PaperMC container

We will first need to make a folder for Minecraft. This is were we will point our image. Those steps can be found by using the documentation on this webpage. The steps should be as followed.

  • Type the command mkdir mc-docker
    • This will create a new folder for our image
  • Type ls to verify that our folder was created
  • Navigate into that new folder by typing cd mc-docker and then type pwd
    • This will show us the path for the folder mc-docker which will come in handy later
  • Navigate to papermc and select Tags. Chose which version of Minecraft you want to install (example: 1.19)
  • Make note of the following command. Please paste in a text editor to make changes.
    • docker run \
    • -d \
    • -it \
    • –name mcserver \
    • –restart=unless-stopped \
    • -e MEMORYSIZE=’1G’ \
    • -v <your working directory>:/data:rw \
    • -p 25565:25565 \
    • -i marctv/minecraft-papermc-server:<desired version>

Please be sure to make changes to fit your working directory, memory specifications, and desired version. Under, “-e MEMORYSIZE=’1G’ \”, please be sure to replace the number “1” with the desired memory allocation. I went with 6 GB of memory for my server. That edit should look like the following, “-e MEMORYSIZE=’6G’ \“. Under, “-v <your working directory>:/data:rw \“, replace <your working directory> with the results from the pwd command we used earlier. For my server, I want ahead and wrote “-v /home/homelab/mc-docker:/data:rw \“. Under, “-i marctv/minecraft-papermc-server:<desired version>” go ahead and change <desired version> with the version number available here. For my server, I went with “-i marctv/minecraft-papermc-server:1.19″. Overall, the command that we should end up with is as follows.

  • Final results
    • docker run \
    • -d \
    • -it \
    • –name mcserver \
    • –restart=unless-stopped \
    • -e MEMORYSIZE=’6G’ \
    • -v /home/homelab/mc-docker:/data:rw \
    • -p 25565:25565 \
    • -i marctv/minecraft-papermc-server:1.19
  • Paste that command in your terminal and hit enter
    • The Minecraft image will begin to download
    • The output should result in Unable to find “marctv/minecraft-paper-server:1.19′ locally. Pulling from marctv/minecraft-papermc-server
  • Verify installation by typing docker logs mcserver
    • Your output should show something along the lines of Found new data pack file/bukkit and Timings Reset
1/17/2023
Note: This image was pulled from online. Re-installing PaperMC will result in an error since I already have it on my system.

Setup DHCP reservation and port forwarding

Minecraft is being hosted on my server. The blaring limitation is that it can only be accessed on the local network. Before we can invite friends from the WAN, I needed to reserve an IPv4 address on my Local area network and then implement port forwarding.

  • Please be sure to refer to your router’s manufacture guide
  • Search how to login to your router’s login page
    • This guide should be helpful
    • Do some research on how you can navigate to DHCP reservation & Port Forwarding
  • Navigate to the section for DHCP Reservation
    • Select the option to add an address reservation
    • You may have a list with your server’s IP address and device name. If not go ahead and type your server’s info under IP Address, MAC Address, and device name
    • Example: IP Address: 192.168.0.20, MAC Address: 1F-CE-10-79-02-70, Device Name: test
    • Apply changes
  • Navigate to the section for Port Forwarding
    • Create or add a new service
    • Your server might already be listed here. If not use the following steps.
    • Provide a name to your service (ex: Minecraft Port Forwarding)
    • Select TCP/UDP for the Protocol
    • Under External Port Range, type 25565
    • Under Internal Port Range, type 25565
    • Under Internal IP address, type your server’s IP Address (ex: 192.168.0.20)
    • Apply changes

Binding your public IP Address with DuckDNS

Before I gave my friends a Server address, I wanted to avoid any hiccups with my ISP. I don’t know when I will be assigned a new public IP Address. I don’t want to pay extra money for a static IP Address so I’ll stick with whatever they assign me. There is a service called DuckDNS that will point a DNS (sub domains of duckdns.org) to an IP address of my choosing. In this case, my public IP address. This is a great service because we can configure it in conjunction with a container to constantly check if my IP address was updated. This will then point the subdomain to that new address without me having to manually change it.

  • Create a DuckDNS account
  • Make note of the given token for later use
  • Under domains, create a domain and select the option add domain
    • If the domain is already in use, please create another
    • Example result: success: domain temporarytest.duckdns.org added to your account
  • Your public IP address is now listed under current ip

Installing DuckDNS image

The final step in configuring the server requires that we install the DuckDNS image. This image will ensure that our public IP address is constantly updated by giving that info to DuckDNS. We can find the install documentation here. The steps are as followed.

  • Navigate the home directory in your terminal
    • Type cd ~
  • Create a folder for the DuckDNS image
    • Type the command mkdir <container name>
      • Ex: mkdir duckdns-docker
    • Type cd duckdns-docker
      • Type pwd and make note of that path. This will come in handy shortly.
      • Example: /home/homelab/duckdns-docker
  • Navigate to docker cli from the linuxserver/duckdns webpage and paste the command into a text editor
    • docker run -d \
    • –name=duckdns \
    • -e PUID=1000 `#optional` \
    • -e PGID=1000 `#optional` \
    • -e TZ=Europe/London \
    • -e SUBDOMAINS=subdomain1,subdomain2 \
    • -e TOKEN=token \
    • -e LOG_FILE=false `#optional` \
    • -v /path/to/appdata/config:/config `#optional` \
    • –restart unless-stopped \
    • lscr.io/linuxserver/duckdns:latest

This command will install the container into our Linux server but we must make a few changes to ensure that we don’t run into any issues. Under, “-e TZ=Europe/London \” replace “Europe/London” with your time zone. For my server, I went with “-e TZ=America/Chicago \“. Under, “-e SUBDOMAINS=subdomain1,subdomain2 \” replace “subdomain1,subdomain2 \” with the subdomain that we created with DuckDNS. An example of this would be “-e SUBDOMAINS=temporarytest \“. Under, “-e TOKEN=token \” replace “token” with the token you were given on DuckDNS. An example of this would be “-e TOKEN=10239570i3-2383-203983-782i-17838siedhbg387b \“. Under, “-v /path/to/appdata/config:/config `#optional` \” replace “/path/to/appdata/config” with the path to the folder duckdns-docker that we created earlier. For my server, I went ahead and typed “-v /home/homelab/duckdns-docker:/config #optional \“. The actual installation should look as follows.

  • Paste the command into your terminal
    • docker run -d \
    • –name=duckdns \
    • -e PUID=1000 #optional \
    • -e PGID=1000 #optional \
    • -e TZ=America/Chicago \
    • -e SUBDOMAINS=temporarytest \
    • -e TOKEN=10239570i3-2383-203983-782i-17838siedhbg387b \
    • -e LOG_FILE=false #optional \
    • -v /home/homelab/duckdns-docker:/config #optional \
    • –restart unless-stopped \
    • lscr.io/linuxserver/duckdns:latest
  • Press enter and let the installation process
    • The first output should be unable to find image ‘lscr.io/linuxserver/duckdns:latest’ locally latest: Pulling from linuxserver/duckdns
  • Once completed, type docker logs duckdns
    • Results should show you Your IP was updated at Day, Month, Day of the month, Time, Timezone, Year
    • Example: Your IP was updated at Tue Jan 3 20:42:26 CST 2023

Joining the sever in Minecraft

The hard stuff has now been completed. We only need to launch Minecraft using the same version we selected earlier and add the server under Multiplayer.

  • Launch Minecraft
  • Select Multiplayer
  • Select Add Server
  • Under Edit Server Info, enter a Server name and Server Address
    • Server Name: Test Server
    • Server Address: temporarytest.duckdns.org
  • Select Done
  • Under Play Multiplayer, click on your new server and then select Join Server
  • Enjoy!

Send your subdomain (example: temporarytest.duckdns.org) to your friends so that they can join as well. Remember to only give this subdomain to those you trust. Anyone can still ping this subdomain or do a tracert and figure out what your public IP address is. Type ping <your subdomain> in the terminal to give it a test.

White edits are my public IP address

Enjoy your new Minecraft server.

Useful commands

I ran into issues with a friend not being able to join. We confirmed that the Server address was being typed correctly yet they couldn’t join. This happened while others were playing on the server including myself. I left the game and had trouble rejoining. I did some troubleshooting and everything seemed to be working fine on the server. I was able to ping my public IP address, server’s local address, and subdomain. I confirmed that Port Forwarding was not deleted on my router. Ultimately, a reboot of the containers fixed the issue.

  • Type docker stop mcserver
    • wait until you are able to type again
  • Type docker stop duckdns
    • wait until you are able to type again
  • The commands above will stop the containers running acting as a reboot
  • Type docker start mcserver
    • wait until you are able to type again
  • Type docker start duckdns
    • wait until you are able to type again
  • This will reinitiate the containers that were stopped a few moments ago. Any issues with the Minecraft container or the duckdns container should be resolved


No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *