Docker
It’s 2022, per application VMs are out and containers are in! We’re at chapter 2 of the tech buzzword catalogue except Docker is actually cool. NetworkChuck has a great introductory video for Docker and Docker networking and it’s recommended to watch those first before continuing.
Pre-Requisite
Within this tutorial we will deploy a Minecraft server, configure backups and a monitoring dashboard with a single compose file.
You will need the following:
- A copy of our Docker compose template
- A VPS / Dedicated host with sudo / root access
- A working Docker deployment
Installing Docker
We have already covered how to deploy Docker to a VPS within our lab series, you should follow this guide if you have not got a working instance. Other great resources for this exist within the DigitalOcean Community forum.
Deployment
For the sake of simplicity this tutorial will be entirely from the linux command line however it should work without any issues in platforms such as Portainer, if you haven’t already SSH into your server.
The first step is to download a copy of our compose.yml file, you can fetch a copy using the following cURL command.
Using nano
or vi
you can edit the contents of the file and make changes as required
There are a couple of lines that you should pay attention to when it comes to customising how this file works.
The first line for consideration is line 7 "25565:25565"
.
- Editing these values will change what ports are exposed on your local machine. You only normally need to change this if you’re running multiple Minecraft servers e.g. Bungeecord.
The next line you can alter is line 10 MEMORY: 4G
.
- Setting this value to something between 4G and 12G tend to offer the best results, the avg server shouldn’t need more than 8G assigned.
The next line you can alter is line 13 TYPE: PURPUR
.
- This defines the jar file used to host your Minecraft server, two of the most common types are
PAPER
andPURPUR
but there are multiple other values that can be assigned her based on the type of server you wish to run.
The next line you can alter is line 27 "8180:8080"
.
- It’s only recommended you change the left hand value for this service if you’re currently using it for an alternative solution. You should take note of these port changes as you may need to reference them later on.
The next line you can alter is line 27 "80:3000"
.
- It’s only recommended you change the left hand value for this service if you’re currently using it for an alternative solution. You should take note of these port changes as you may need to reference them later on.
The final line you may wish to alter is line 53 BACKUP_INTERVAL: "1d"
.
- Define how frequently your server is backed up, for a small server 1d is more than enough but for larger public environments you may wish to move this to every 4 hours.
Now that the config has been adjusted as required the next thing to do is to spin up your containers, this can be done using the below command.
You can confirm if the containers have been started by using the docker ps
command.
If one or more services produces an error, you should try using the below command to ensure nothing is currently running on the specified port.
Importing Worlds
Ensure your docker instance is stopped before you change the world file to prevent corruptions.
If you do not have a Minecraft world you would like to bring over you can skip this step
Firstly navigate to where your world is stored, if you’re world is in a singleplayer state this will be located in your .minecraft\saves
folder.
- You should compress your world utilising a
zip
folder, the steps will vary slightly based on OS - Start a SFTP shell using
sftp username@server-ip
- Navigate to
/svr/minecraft
usingcd /svr/minecraft
- Upload the file by using
put /path/to/folder/world.zip /svr/minecraft/world.zip
- This may take a few minutes depending on your internet upload speeds
- Exit the SFTP session using
exit
- Start an SSH sessions using
ssh username@server-ip
- Install the
unzip
package usingsudo apt install unzip
- Unzip the world we just uploaded using
unzip /svr/minecraft/world.zip
Now the world has been uploaded you can start the server and your world should be loaded, if your server is not using your uploaded world ensure you have the correct foldername specified within the server.properties file (this is case sensitive).
Monitoring
This section is optional however as our docker-compose file already contains the required info to configure this we will do so in this guide. If you do not care for monitoring this can be ignored.
Prometheus
Prometheus is very similar tool to InfluxDB (a tool we use in our lab series) and it is used for metric collection for a given source. Everything within our docker instance should already be configured as required you only need to ensure prometheus
is running when you use the docker ps
command.
Grafana
For our installation Grafana can be found in the browser via http://server-ip (utilising port 80 by default unless changed within the compose file).
The process of setting up Grafana and adding sources / dashboards can be found within our lab series.