Okay i’ll admit i don’t play video games as much as i used to unfortunately i have more expensive hobbies now like photography being a tech youtuber and getting married but i used to play a lot of video games yet somehow i’ve eluded the most popular game ever minecraft this Was until one of my friends messaged me like hey can you spin up a minecraft server for my kids to play on i was like you want me to take my production server that i use for a nas for all my important documents and videos and also run extremely important Services and websites on to run minecraft hell yeah let’s do it so with my limited knowledge of minecraft i looked up what it takes to run a server and apparently not much so i got my hands dirty and ended up going with an image of docker and It’s honestly super easy to do so i’m going to share with you what i did to set it up and the different changes i made to make sure that it runs smoothly to add plugins or mods and to back up your world in case something happens or you want to Transfer it so let’s talk about that and see what i did Okay so i went into this not knowing really much about minecraft and after doing some research it doesn’t seem that running a minecraft server is really too hardware intensive so i’m running this on my backup server which is extremely low power it’s a xeon 1240 l processor 4 cores 8 threads with 16 gigs of ram running open media vault so yeah obviously nothing crazy at all now i wanted to run this in docker because docker is extremely convenient to use it’s easy to spin up and migrate to other systems if you need to now if you aren’t as familiar with Docker don’t worry we’re going to cover pretty much everything step by step so just follow along and you will get there i promise also we’re going with docker compose for this it just makes things easier so make sure you have docker compose installed i’m not going to go Over how to install docker on your system or docker compose or anything it’s pretty straightforward just google your system installing docker and once you have that ready come back to this point i went with an image from docker called it cg or it’s g slash minecraft server it’s extremely Popular it works great so i’m gonna link everything down below if you don’t catch everything it’s okay all the steps and everything i use will be in the comments below or the description below so the version of minecraft we are using is the java version now this is not cross-play Compatible this isn’t compatible on consoles so make sure before you do this that the version you’re running is the image that you’re using they also have an image if you’re running the microsoft version for cross-play compatibility uh you can run that bedrock version i think they call it but This is the java version this is for pc only so if you’re using the bedrock version a lot of this stuff will carry over but this is purely for the java version so you’re probably assuming the first thing you want to do is get your docker compose yaml set up but We’re going to do something first we’re going to set up our file system just to prepare ourselves for the ammo file and getting everything installed so first step is to ssh or get into the terminal or the gui interface of the system you have running docker on now I’m going to do everything in the command line which is usually against what i do i like gooeys i like working in them i use portainer for docker but i want to make sure this is usable by everybody regardless of whether you’re using portainer or some other docker orchestrator or Just straight up using the command line as long as you’re running docker and docker compose on your system these commands will work all right so my screen is divided up into three sections right now the top left section is my desktop that i’m working on my local Machine the bottom left is my server that i have ssh into that is running docker so you’re going to want to do that and the right is my docker compose yaml file we’ll get to that in a second so the first thing you’re going to want to do is create a directory On your server to house your yaml file and pretty much the base file system so that’s we’re going to do i am in my root directory right now here’s a list of everything what we’re going to do is we’re going to go into our home directory you can do this Wherever you want but that’s just where i’m going so we’re now in our home directory you can see we have nothing there i’m going to make a directory called minecraft you can again substitute whatever naming you want i named minecraft because we’re running minecraft i’m also going to create a Folder in there called plugins you’ll see why later on in the video so let’s uh cd into our newly created minecraft and then we’re going to make another directory called plugins plug-ins now next thing we’re going to want to do is create a volume it’s extremely easy to do type docker volume Create and then i named it minecraft data again you can name it whatever you want to do that it creates a docker volume called minecraft data so now we are ready to look at our yaml file now this is what tells docker compose what to run what image to use what volumes to Use a lot of settings on your docker container and it’s just a more simple way of running a docker container running a regular docker command versus using docker compose it’s preference i personally like docker compose so that’s what i’m going with so you can pretty much copy The exact yaml that i have here you’re obviously going to change a few things but it’s really straightforward there’s not much to it now you’re just going to want to make sure your yaml file is called docker hyphen compose dot yml because that’s by default what docker Compose is going to look for when it spins up your container so right here we’ll go through it version three uh services we only have one called minecraft the image we use make sure that’s itcg slash minecraft hyphen server and volumes this is the first thing that I want to touch on now remember we just created our volume called minecraft data whatever you called it make sure that’s specified here colon and then slash data this is what it’s going to be referenced to inside the container this does not change the only thing that would change Is this and what you named it in the step before now the next one this isn’t going to be a named volume this is going to be a binding mount so remember before when we set up our plugins folder well that’s what we’re specifying here now You can also create a mods folder i’m not personally using mods in my minecraft server if you want to use mods just do the same thing except with another folder called mods but here you specify that same directory remember we did home slash minecraft plugins and that’s what your list here and then Colon slash plugins ports you can use the default one which is 25 565. if you want it to be a different one on the outside you would change it here on the left but make sure the right one is 25 565. environment variables the only one you really need is this eula true The next ones are ones that i would suggest changing so i am using type bucket you can look in the documentation on github for the docker image that i’m using you can have different types of servers if you leave this blank it’ll be just a standard vanilla version of Minecraft with no plugins or mods or anything but if you want to use the bucket style plugins then you’ll want to set the type to bucket ops or ops or operators for your server i would go in and set this to yourself or your minecraft account name just to Make sure you are a operator for the server by default now if your server is externally facing and you want to be accessible outside of your lan i would strongly recommend setting enable whitelist to true as well as enforce whitelist to true that way you can specify exactly which players You want to be able to access your server and if you don’t do this pretty much anybody who has your ip can’t access your server so if you want that cool if you don’t make sure these are set and the rest is default the last thing is volumes just Make sure you have this volumes section inside your yaml with the name of the volume you specified before and set external to true and that’s it that’s our yaml file that’s what’s going to build our server it’s pretty much all you need for the most part if you want To set up a basic server all you have to do is put that on your server and run it so that’s what we’re going to do it’s pretty easy you can do it however you want to do it if you want to download a program that ftps it over if You want to get a usb stick and plug it in and put it on there yourself do it that way i use scp so it’s a pretty easy command scp also make sure you’re in the directory where the yaml file is this is on my desktop so i’m in my Desktop in the command line so scp the name of the file is docker compose.yaml then where you want to log into so it’s going to be root at my ip address for my server which is 10.0.0.44 colon and then the directory location that you want to drop this file in so we Want to put it in home minecraft and we’ll just leave it there so hit that enter the password for your server and just like that it should be there so if we go down to our server list our docker compose is there so honestly after all this you really don’t need to Do much more if you just want to spin up the server all we have to do is run it so that’s what we’re going to do and the command we’re going to run is docker compose up d and force recreate you don’t need this force recreate in there But it’s good to have a habit of putting it in there just in case the container already exists this will kill it and then recreate it so we don’t have one yet but it doesn’t matter so we’re going to run that and it is going to build it now the First time you run it is probably gonna have to download the image which might take you know a minute or two depending on your internet connection but um ours already has it so it says it’s done and we can go check on that by checking portainer okay so remember i said i’m Using portainer as my orchestrator now this just makes it easy to check on what’s going on the statuses you can also do this on the cli but i like to use sportainer for this uh starting up takes a little bit depending on your processing power it could take a minute Or two but that’s okay so you can see our container that it’s spun up here minecraft underscore minecraft one if we go over to volumes you’ll see the volume that we created and you’ll see that it’s using this and you can also see the ports that we published and that it’s Using the 25 565 port that minecraft is supposed to use so we’re going to give it a couple seconds and make sure that it’s up and running we can go ahead and open up minecraft while we wait see what’s going on here we’re at 71 percent all right now remember how i Said you can install plugins if you’re using bucket or whatever type you’re using now i’m using bucket and we created that plugins folder and that’s where we’re going to drop them now it’s extremely easy just navigate to the bucket plugins homepage you can scroll through there’s a crap ton of them out there And it’s extremely easy all you’re going to want to do is go into the one that you want click on it download the latest file and it might give you a warning but it’s just a jar file it’s okay and again just like before we’re going to scp that File into our plugins folder that we created which was in home slash minecraft remember we have a plugins folder so any jar file that you put in there will be loaded into your server whenever you reboot or start it up so extremely easy to do i have a few that i’ve loaded in There if i can do it you can do it all right minecraft is up and running so if we go into minecraft we go to multiplayer proceed scanning network but we’re going to go ahead and add a server we’ll call it minecraft server and the server address is the Address of your portainer or your docker server so in my case remember it was 10.0.0.44 if you’re using the default port address then you don’t have to enter that here click done and look at that instantly found it i can go ahead and join the server and Just like that i am playing minecraft on the server i built in docker so now we have a crap ton of stuff on the screen now to look at the stats of the server and whatnot you can look at it and determine uh the quality for yourself But it does run pretty freaking good and if that’s all you want from here then you’re done you can stop the video now and you have a minecraft server congratulations but i didn’t stop there i wanted to make sure that my minecraft world was backed up properly and if something happened i Wanted to make sure i had a backup and i knew how to restore the world in the event of a crash so that’s what we’re going to talk about now okay sorry to interrupt but i’m actually editing this video right now and i’m realizing that i didn’t include how to actually access Your server’s command line interface and actually interact with the server to white list players or change settings on the actual server so let’s talk about that don’t worry it’s a one-liner just make sure you’re remoted or ssh into the server that’s running your minecraft server and you’re going To run docker exec hyphen i your container name then rcon hyphen cli and that’s going to put you into the command line of your minecraft server so from here you can run all the commands you can look up a list of everything you can do but for example you can add somebody To the white list white list add and then their player name that player does not exist in the minecraft world uh about regular john okay john is now allowed to uh access the minecraft server you can also change the difficulty of the server let’s make it a hard And now just like that the difficulty of the server has been set to hard and yeah once you’re done just hit ctrl d and you are finished so that’s it i will return you to the regularly scheduled program so the general premise behind this is that Yes i am running backups of my portainer virtual machine which will in turn back up the minecraft server but i also run other things on portainer so if something happens in my minecraft server and we need to reset it to earlier in the day or the previous day i don’t want To kill everything else in my portainer virtual machine just to reset minecraft so what we’re going to do is individually back up the minecraft data volume within our minecraft server container and then if we need to restore just that minecraft data we can pull in a archived version of That minecraft data volume and then restore it and it’s honestly pretty easy to do now the first step is to create a consistent backup of your minecraft data docker volume so let’s talk about that so first thing i did was created a directory inside the etc folder again You can do this wherever you want you can name it whatever you want but i put in etc and i called it script so we’re going to cd into there oh sorry cd and i’ve transferred over my script that i am using to run these backups so If we look in there you see a backup dot sh let’s take a look at that maximize this so we can take a look so i’m not going over it line by line but for the most part you’ll see here that you can pass some variables so with v You can pass some volume names that you want to back up within a specific container you can pass a to true if you want to backup everything in that container output directory this is where the backup tar file is going to be stored c the container name r this is Going to be if you want to delete the directory every time you create a new backup so if you only want to keep one version set this to true and you’ll just keep the latest version now by default it’s false so if you don’t pass anything it’s just going to keep pretty much Everything so yeah and d the number of days you want to keep old files for so if you set this to seven it’s gonna keep every backup version for the last seven days so yeah this is just declaring the variables setting defaults a lot of Boring stuff blah blah so we get to here this is the first thing of real significance this is where it’s going to create our directory for housing our backup tar files so we passed in the o variable which is where we want to store it and it’s going to create a Subdirectory in that location with the container name that we also passed which you can see here the next thing it’s going to do is check our days back variables so again if you passed in seven it’s going to look at all the files that are older Seven days old and delete them next up if you passed clear it’s going to clear everything from there so it doesn’t matter what your days back was if you have clear set to true it’s going to wipe everything and here is where it runs the command to Back up the docker volume i’m not going to walk through this but basically it’s saying take the volume that we specified or the comma separated list of volumes we specified take the data out of them wrap them in a tar file and dump them in the directory we specified and then if Everything went great spit out an output again all of this stuff is going to be linked in the description below now if we want to run this periodically we’re going to want to enter a cron job and it’s extremely easy to do all you have to do is enter cron tab hyphen e That’s going to bring up your crown tab where you can enter cron jobs and specify how often you want them to run so go to the bottom and you can look up the syntax for creating a cron job i’ll explain it pretty briefly here the first section is to declare the Frequency that you want to run now personally i have it running twice a day at midnight and at noon so the syntax for that is 0 space 0 comma 12 which is the hours you want to run then we want that to run every day every month for every year i Think then we specify the command we want to run and that is simply just bash the location of the script so this is wherever you put it mine remember was etc slash scripts slash backup dot sh and then we specify our variables so the volume we wanted to Back up was minecraft data the container was minecraft underscore minecraft underscore one the output directory is wherever you want to store it so we didn’t create a location for this yet but i’ll go back and do that so we’re going to store it in etc scripts Backups and we don’t want things to be deleted false by default but i’m going to specify it and we will keep these for let’s say seven days ctrl o save yes and exit now we do have to create that backups folder we’re already in etc script so we just have to mk beer Backups boom and just like that our directory is going to be backed up with tar files of our minecraft data twice a day and we can restore it if something ever happens now let me show you how that’s done so we’ve just switched over to my production minecraft server which is Where i have this running and you’ll see we have a bunch of backups from the previous day you’ll see a lot from today because i was testing things but here’s our tar files from our minecraft server so what i’m going to do is transfer one of these backups To my backup server and we’re going to restore our production minecraft server on our backup server so you may not use it like this you may restore it to another container within your same server so that would probably be easier honestly but let’s do that so let’s pick A tar file and scp that over and we’ll put that in our backup like we’ll assume this was a backup run remember we did etc scripts backups actually it would put it in the container name but for right now we’re just gonna put it in backups that over And it’s about 300 megabytes so it actually took like five seconds to run let’s close that out clear and we will cd into our backups folder and you can see our tar file is there now we just need to run the command to restore that tar file to our containers Data folder okay so now we need to restore our backup and this is the command that we’re going to run now i know it looks pretty intimidating but let me explain it’s not too bad you’re going to run docker run rm volumes from which is essentially going to remove volumes from the Container specified and that container is going to be your minecraft server container in my case it’s minecraft underscore minecraft underscore one then you’re going to pass essentially a temporary volume called backups and this is going to point to the location of your tar file so remember we saved ours To etc scripts backups if you’re running the cron job it’s going to save to backups slash the name of your container but remember we just manually transferred it to that backups folder the next step is to run a bash command from within the container and that is Within quotes here you can see the first thing we’re doing is cding into our data directory which is where we want to unpack the tar file then we’re running the tar command to uncompress it and we are specifying the location of that tar file now remember we passed it as the Slash backup directory within the docker container so we specify slash backup and then the name of the tar file now last thing you’ll see here is this strip one we’re using that because we have a directory in front of our tar file that we want to strip off and you can see we Only have one we have slash backup if it’s even deeper maybe it’s like slash var slash backup in that case you do strip two but in our case we are doing strip one and when you run that it’s going to unpack everything into that location and You should be good to go now let’s go back into portainer and start up our container give it a hot second remember it took a couple minutes let’s load up minecraft again okay we’re up and running so now we can go back into minecraft multiplayer proceed and look At that our server is back online again you can see my new message of the day that’s an environment variable if you want to pass that and let’s go ahead and connect and look at that i am back in my world with my little fort that i’ve created along with all my items Just like i had on my production server so we created a minecraft server using docker compose we have it backed up twice a day we learned how to transfer a file over or restore from a backed up file and we’re pretty much set so that’s kind of all i have for you guys Today i hope this was informative i hope this helped out i know there might be other ways to do it but this has worked pretty great for me over the past couple of weeks so i’m honestly proud of it and i think it’s running pretty good so if you want To copy this verbatim go ahead if you have any questions about it feel free to ask below in the comments or join the discord which is also in the description uh we have a bunch of people hanging out on there i’m always on there so feel free to Stop by and ask some questions or share about your projects but that’s all i have for you today i hope you enjoyed it if you did be sure to drop a like below if you like content like this please consider subscribing thank you so much for watching i will see you In the next one Video Information
This video, titled ‘Minecraft Server in Docker – How to Setup/Backup/Restore your Minecraft Server’, was uploaded by Raid Owl on 2021-12-24 21:36:12. It has garnered 63106 views and 1324 likes. The duration of the video is 00:24:44 or 1484 seconds.
A friend of mine wanted me to create a Minecraft server for his kids to play on so I figured I’d give it a shot. It was honestly easier than I expected and even added a process to backup and restore if needed.
Guide – https://docs.google.com/document/d/1-4R_JlZqUxP8IyDOwqY4MWUf0v57qFEdSvPCtzRauag
Support the channel on: Patreon – https://www.patreon.com/RaidOwl Discord – https://bit.ly/3J53xYs Paypal – https://bit.ly/3Fcrs5V
Affiliate Links: Ryzen 9 5950x – https://amzn.to/3z29yko Samsung 980 2TB – https://amzn.to/3myEa85 Logitech G513 – https://amzn.to/3sPS6yv Logitech G703 – https://amzn.to/3sATW5R WD Ultrastar 12TB – https://amzn.to/3EvOPXc
My Studio Equipment: Sony FX3 – https://amzn.to/3qq4Jxl Sony 24mm 1.4 GM – https://amzn.to/3mA1TEK Tascam DR-40x Audio Recorder – https://amzn.to/3EvTPeq Rode NTG4+ Mic – https://amzn.to/3JuElLs Atmos NinjaV – https://amzn.to/3Hi0ue1 Godox SL150 Light – https://amzn.to/3Es0Qg3
Join the Discord: https://discord.gg/CUzhMSS7qd
0:00 Intro 1:20 My Setup 3:20 Let’s get started 5:32 docker-compose.yml 10:00 Run the container 11:31 Plugins 12:26 Connect to your server 13:39 Access your Minecraft server’s cli 14:54 Automatically backup your world 20:02 Restore from a backup 23:43 Conclusion