I woke up this morning not feeling like I was enough of a hipster admin so I decided to write this keyword..er.. educational post about docker.
I am going to spare you the explanation of what docker is and what it does. That you can find from other places. So lets say you have docker installed somewhere and you want to try running your own minecraft server. You could do something like this:
docker run -p 25565:25565 -e EULA=TRUE itzg/minecraft-server
That will download a docker image that its created for running minecraft and start it. That was pretty easy huh?
Now lets say you felt that you just weren’t getting the IO performance that you wanted out of that nifty new server and also you would like your map to persist through restarting the container. You might try this:
docker run -p 25565:35565 -e EULA=TRUE -v /dev/shm/minecraft:/data itzg/minecraft-server
NOTE: When you run docker images from the docker registry you are essentially downloading and running untrusted code on your system. Please be careful.
Now you are running minecraft on ram. You however, are a savvy admin and realize that in the event your server reboots you will still lose your prized dirt hut. You quickly decide to set up some quick backups. You could set this up in cron, but thats not quite cool enough so you decide to use systemd timers instead. You fire up your text editor and produce the following files:
/etc/systemd/system/backupcraft.timer [Unit] Description=Minecraft backup timer [Timer] OnBootSec=15min OnCalendar=*:0/5 [Install] WantedBy=timers.target /etc/systemd/system/backupcraft.service [Unit] Description=Minecraft backup timer ConditionACPower=true [Service] Type=oneshot ExecStart=/usr/bin/rsync -a /dev/shm/minecraft/ /backup/minecraft/ Nice=19 IOSchedulingClass=best-effort IOSchedulingPriority=7
You follow that up by starting the timer:
systemctl enable backupcraft.timer systemctl start backupcraft.timer
You check to make sure the timer is working:
systemctl list-timers --all
After the backup runs, you check to see if it worked as expected:
ls -la /backup/minecraft
Now you can sit back and enjoy some speedy minecraft until your hard disk fails.
NOTE: Yes I know this is not a real backup strategy, and no I am not going to explain one here.
CC-License: CC BY Photo: Markus Spiske / raumrot.com
Opinions expressed are solely my own and do not express the views or opinions of my employer.