If you’re watching this video you more than likely are running your own Minecraft server and you’ve thought to yourself I kind of know what Docker is and what a Docker container is and I want to create my own Minecraft container image so if that is the reason you’re watching this video Welcome in This video I’m going to show you two different ways to create your own Minecraft server container image the first way I’m going to show you I’m going to show you how to use an existing Minecraft server container image to build off of and create your own maybe You’re already using one like the itg Minecraft server container image and you just want to modify it a little make it your own and then the second option I’m going to show you is creating a Minecraft server container image from scratch using a vanilla plane OS so if You’re not familiar with what Docker is or what a container image is I actually have a YouTube series called Running Minecraft in production and the first video is labeled how to run Minecraft on Docker in that video I go really far into in depth on how to install Docker And Docker desktop on Windows and also what Docker is and what a container is so if you’re curious go ahead and check that out but if you already know continue watching the majority of this video is going to be done using the docker CLI but where possible I will use Docker desktop and Docker CLI so you get the best of both worlds so like I said in the beginning of the video I’m not going to show you how to install Docker but I do have a YouTube video called Running Minecraft on Docker that goes over that in depth in the spirit of Keeping this video beginner friendly where possible I will use Docker desktop but a lot of these things that we’re doing building a container image we need to use Docker CLI so the first thing we actually need to do is we need to pick a place on our computer that we’re going To work out of so I have created a folder on my PC called Minecraft and that’s going to be where I’m going to work from and then I’m going to open up visual studio code if you’re not using visual studio code I highly recommend You go ahead and download it it is a a great tool when you’re working with any kind of code whether that be just programming it is a great tool for any of the kind of stuff that we are doing and then I’m going to go over here to The Explorer icon and I’m going to hit open folder and I’m going to navigate to that folder that I had created where I want to work from and I’m going to select that folder and now you can see here on the left hand side I’ve got that Minecraft folder open and so that’s Where we’re going to work from for this for the rest of this video so the first example we’re going to go over is creating your Minecraft server container image from another Minecraft server container image so to get started I’m going to create a new folder and I want to call it existing Container and then because I’m going to have multiple scenarios here I want to keep the files separate and then I’m going to create a new file and I’m just going to call this Docker file with a capital D and you’ll see here in vs code that the little Docker symbol has Actually appeared next to my file and that is because I have installed the docker extension so if you’re using Visual Studio code and you go to the extensions icon here and you search for Docker you’ll see the docker extension that you can install and it helps you With formatting so the docker file is the file that contains the script or the code or the instructions on how to build a Docker image if we think about Docker containers first comes the docker file then comes the docker image and then comes the docker container so we write a Docker file how to build an image we build an image and then we use the image to run a container 99% of the time you are creating your own Docker images you are going to specify the first command in your Docker file as from and this is telling Docker what base image do you want to use existing container image to build off of we’re essentially copy and Pasta in another image and then adding our own sauce on top so because this first example is is showing you how to create your own Minecraft server container Image from an existing one that’s what we’re going to use as our base image an existing Minecraft container so if we go to hub. deer.com right there’s a fairly popular Minecraft server container image that a lot of people use called itz G and it’s pretty heavily customized with A lot of different options so in this example maybe you’re using this container image or another container image and you’re not NE necessarily happy with everything that’s going into it or maybe you want to make some changes you want extra things to happen on Startup or you want to add some extra Files to The Container image well that is what this scenario is for and that’s when you would create a container from another existing Minecraft container image so let’s go ahead and do that so we’re going to copy the name of this container image and we’re going to use That as our from so now we’re telling Docker when I build this image image start from the itcg Minecraft server container image and then build on top of it the next step is we have to start adding our files to our Docker image any scripts we might want to run when the Container starts so to do that we specify what’s called working directory or work dur and then we provide a path and this would be a path within a container so if I provide slash app then other Docker commands like copy or run will happen as if they were in this Directory they’ll be executed from this directory a lot of people like to say this is the equivalent of CD or changing directory into this directory when Docker runs the commands to build the image so for this example the files that I want to copy in to this Minecraft Server container image are a white list right I have a white list already on my Minecraft server and I just want to add that to the container image so it’s there every time it starts so I’m going to put my white list here so now what we Want to do is we want to provide the copy command and copy has two options source and destination that we can provide so the source is going to be relative to this Docker file let me just put that in there uh whitel list. Json and then where in the container Would you like to put whitel list. Json well if you’re familiar with the itz container there is a documentation link here on their Docker Hub page and when you go there they have a data directory documentation section and all the Minecraft data gets put into the slash Dat directory in this container and it just so happens that whitel list. Json also gets read from slata so the destination inside of the container that we would like to put wh list. Json is is going to be slash data and then maybe I’ve got a script I want to run right so I’ll do like build info. shell and this will be a bash script that I want to run every time my container starts and maybe we’re just going to Echo some information into a text file so every time the container starts we’re going to go ahead and we’re going to create build Info. text and it’s just going to have this information built by the pseudo inside of the file so then we want to copy that in as well so we’re saying build info Dosh and we want to put that somewhere on the computer maybe slash opt so then We come to the Run command and we can pass in a command so run is going to execute a command on top of the current image so if we look at what we’ve done so far we are going to build an image using itcg Minecraft server as the base We are going to change into the directory app inside of the container as we build it we’re going to copy whitel list. Json from our working directory over here into /data on the container and we’re going to copy buildinfo Dosh show over here from our working directory into SL opt in the container Now because we specified a working directory anything we run is going to run from within this directory in the container SLA so anything we provide here if it has a path it needs to be relative to SLA within the container and run is normally used for installing dependency or running build steps Anything that’s needed during the build process you wouldn’t use this to execute say a script that you needed to execute every time the container started this would be something you needed only during the container build process so for us right we’re going to install JQ because the base image doesn’t have JQ Installed by default and if you’re not familiar with JQ it allows us to parse Json and then we’re also going to execute build info. show so again we’re only doing these when we build the container image not when we run the container image and then we’re going to Provide Expose and a port number now this is telling the container image uh when the container starts what port are we going to listen on for incoming connections so by default Minecraft is 25565 now we’re going to stop there and that’s all we’re going to put in this Docker file because we’re using an existing Minecraft server container image to build from so we don’t need to provide anything extra such as how to download Minecraft into the Container or how to start the Minecraft server because that’s already happening because we’re already using a Minecraft server Container all we’re doing is adding some extra files and downloading some extra EXT ra software into the Container to make our lives a little easier now if you wanted to right and we’ll see this in the next example where we create one from scratch you could provide CMD and then an executable to Run right so this would be a command that runs every time your container starts but it could be overridden by a user or we could provide entry point so we don’t need those two right now we will use those when we build our own Minecraft server container image from Scratch in the next example but for now this is all we should need so with our Docker file buil we’re ready to start executing the docker build command to then go ahead and build it so what I did just there in Visual Studio code is I Went up to the top to terminal and I hit new terminal you could certainly run this through Powershell or command prompt or whatever you choose whatever flavor of terminal you’re comfortable with so from this working directory Minecraft right I’m going to go into existing container I’m just going to do A Docker PS and there are no containers running I’m going to do a Docker image LS to list the images on my machine currently there are none so to build a container image from a Docker file we use the docker build command and we’re going to want to pass the flag DT and This allows us to name or tag is what DT stands for our container image and so I’m going to call it custom- MC short from Minecraft and I’m going to add colon and this part’s optional and a version number so maybe this is version 0.1 of my container image and then I’m Going to specify where my Docker file exist and because I am running Docker build from within this existing container directory which is my working directory I’m just going to specify here with a DOT and so now Docker is building my Docker container so we can see it says building From docker.io itcg Minecraft server and then it changes directory oh I had a typo in my shell script here let me run that again all right and it has finished so I’ll clear the screen and now when I run a Docker image LS to list the images On my machine I have an image called C custom- MC and it is version or tag 0.1 so I should now be able to run this image so if I go to images and Docker desktop we’ll start with Docker desktop and then I’ll show you Docker CLI I can See my image is here right and I can hit the play button or the Run button and what do I want my container to be named when it starts we’ll just say Minecraft we’re going to do 25565 for the port and we haven’t covered volumes yet but environment variables we need to provide EA and a value of true and this is a requirement for Minecraft to start and the only reason we can use these environment variables is because we built our container image from the itg Minecraft server container image which has these environment variables already preconfigured for us to set and you can See that in the documentation for the itz Minecraft container if you go to the variables section of the documentation and you look for the EA variable must be set to true so we’ll go ahead and we’ll run that and Minecraft should start up for us so the equivalent Docker CLI command To run this container would be Docker run and then our arguments so we’re going to do- P for Port we’re going to map the port on our system to that Port we exposed to 5565 we’re going to do Dash e to pass in that EA equals true environment variable We’re going to do Dash D so that our container runs in the background and doesn’t run in the foreground and take over our terminal session here and then we’re just going to pass the name of our uh container image that we created and I’m doing this after the fact I’m Recording this after the fact but it’s named existing Minecraft for me and then we’ll do Docker run and then can do Docker PS and we can see existing Minecraft running and it should start up the same way you see in Docker desktop so Minecraft should be up right Now but before we attempt to connect let’s make sure that the things we added to the itcg container image to create our own image actually took effect so the first thing I want to look for is I want to make sure JQ got installed and that the build info. shell script got Copied over and run success successfully and if we look at that it should have created a file in/ opt called buildinfo doxt so over here in the Minecraft container let’s go to files and let’s go to SL opt and we can see that we do indeed have the build info. shellscript and Build info. dxt so if we go to the terminal and we go into slop o opt and we do see our files there we can inspect buildinfo txt and we can see that our script did indeed run successfully and then the other thing we’re looking for is that whitel list. Json file that we put on here so that would go into SL dat and we do see Whit list. Json and if we open it up we do see our white list the way we expect it to be so we have successfully used an existing Minecraft server container image and then added a Few different seasonings as you will on top of the main recipe so let’s go ahead and let’s test our connection let’s attempt to connect and log into Minecraft uh so we can see that the itg container is actually using 1.20 do3 version of the Minecraft server so on my Minecraft client I just Want to make sure that I’m also using 1.2.3 and I’m going to hit play going to go to multiplayer and I’ve got a server here called custom and because Minecraft is running on my local computer I can just specify Local Host and then the port that the container should be exposed and Listening on to 5565 so I’m going to connect and we can see down here I have successfully logged in to my Minecraft container image and as we can see at the bottom of the log I have successfully connected and logged into my Minecraft container all right it’s time to cover the reason you’re Probably watching this video how to create my own container image of my Minecraft server from scratch meaning unlike the existing container example that we just went over we’re not creating from an existing container image that contains the code to run a Minecraft server instead we are going to I’m just Going to create a new f folder here right and I’m going to call it from scratch right so this is my working directory and this is where I’m going to create the docker file for creating my Minecraft server container image so just like we did for the existing container Right in here we’re going to create a Docker file o capital D and that’s it no extension and then we’re going to Define our first command for our doer build and that is going to be from and we’re going to choose our base image so unlike the existing container let me just pull These up side by side right so this is the container image we built earlier unlike that one where we use an existing Minecraft server container image we are going to just use a vanilla operating system container image so we’re going to use Ubuntu and you can see that it’s Kind of finishing it for me and that’s because I have the docker extension installed in vs code so what happens is I can actually because I have this extension installed I can click on this and it’s actually going to bring me to Docker Hub the page for this Container image and on here you know we can look at the supported tags we can look at which are versions of the container image right so there’s latest there’s different tags and there’s different architectures and this is important you never want to try and create a Windows container and run it on Linux and vice versa it’s just not going to work and then I’m going to specify the tag or the version of this Ubuntu container image that I want to build from and I’m going to do 2204 now hold up real quick I just told you that you cannot run a Linux Container on Windows I’m running Docker desktop on Windows how am I running a container built from a Linux image on Windows well you see when you install Docker desktop on Windows it actually runs in an emulated Linux environment so it runs Linux containers if you were to install Docker desktop on Windows and Try to run a Windows container it would yell at you and tell you please configure Docker to run Windows containers to which this day I have never successfully been able to configure that your mileage may vary enough of a tangent back to our build here so we’re going to build our Container image from a base vanilla blank Ubuntu operating system image and then we’re going to provide a new Docker command that you didn’t see earlier in the first example and that is EnV and this stands for environment variables so if we want to set an environment variable inside of our container when it Starts so we’re going to send an environment variable called Debbie in front end and we’re going to set the value to non-interactive now we do this because Ubuntu when we do certain things like install packages or install other software sometimes it has a tendency to Ask the user for a prompt if we’re doing a Docker build we cannot respond to that prompt manually so we set this environment variable in Debian based operating systems so that we are not prompted for those things so this has nothing specifically to do with Minecraft but it helps keep our Docker Builds healthy as we build them so then next we’re going to specify working directory and I’m going to call it Minecraft now this doesn’t have to exist anywhere all this does is tell Docker build when we run the docker build command it tells Docker create a Minecraft Dory CD into it and then run all of our commands from that directory so at the end we will get a container image with a SL Minecraft folder in it or directory so next we’re going to specify run what commands do we want to Run when we build the image not run the container so it’s important to remember run is for building the image things you want to happen only when you build and then there are other commands that we use to perform actions and run commands when we start the container from the Image so keep that in mind there’s a difference there so what we’re going to do is we’re going to install some software right because this is a base vanilla image it doesn’t have all the software required to run a Minecraft server so we’re going to use the package Manager AP or appt to update and install open jdk 17 which is required W get which we’re going to use to retrieve files from the internet when we do our build and then we’re also going to to remove a bunch of files and directories that make our container a lot larger Than it needs to be so we’re pruning unnecessary things to make our container smaller then we’re going to do another run and we’re going to provide another command and the command we’re going to run is the command to actually retrieve our Minecraft server.jar file so we’re Going to run W get which we just installed and we’re going to call it server.jar when it gets downloaded and it’s going to be downloaded into the/ Minecraft folder because that is where we are running W get from when we do a Docker build now this link here who Pooped who who pooped now this link here where did I get this from good question so if you just Google download Minecraft server right you’ll be brought to this page where they have a link to the latest version of the Minecraft server.jar so that’s where I got this Link so if I actually just copy this link address right I can go ahead and paste that in there and now I’m going to get version 1.2.3 of Minecraft when I build my container so unlike the itcg container where we are downloading the Minecraft server.jar every time the container runs We are downloading the Minecraft server.jar when we build the container so that we do not have to download it every time we run it it’s already downloaded then we’re going to run another run command and if you’re familiar with Minecraft you will know that you cannot start a Minecraft server Unless you accept the EA so we’re going to do Echo and we’re going to say EA equals true into a file called ea. txt so what’s going to happen is inside the Minecraft folder the Minecraft working directory in the container we’re going to end up with ea. Txt and that is going to contain this text EA equals true and then when we go to start the server Minecraft will see this file read it see that this is true and allow us to start the server next we’re going to Define expose and then the port number That the Minecraft server is going to listen on so our container will also listen on this port for traffic so when we connect to the server we’re going to connect on this port so by default this is 25565 so that’s what we’re going to set now the next two commands that we’re Going to specify for our Docker file to run when we build the container are CMD and then some kind of action to take an entry point and some kind of action to take now you don’t have to use both of these you can just use CMD or you can Just use entry point but the difference between run and CMD and entry point is that run is executed when you build a container image so I as the owner of a container image I build it and I push it out somewhere to Docker Hub so that People can consume it when I build it I’m including server.jar in the image and then when you consume my container image and you run it that is when CMD and entry point commands are run when the container starts now it’s good practice to normally combine both CMD And entry point and use them together but you don’t have to you can just specify one or the other now the difference between CMD and entry point is that normally um the entry point maybe it would make more sense if I put these in there in in the order that I’m About to explain them in so entry point is normally the process to be executed inside of the container so that would be Minecraft and then CMD is normally the default set of arguments that will be supplied to the entry point process right so if you’re familiar with how we Execute Minecraft we run Java and then we pass in some commands like maybe server.jar right so Java would be the entry point and then all of those extra arguments would be under CMD so let’s see what that looks like um so if we pretended we didn’t really want To use entry point right the command we’re going to use to start our Minecraft server when the container starts is Java and then these 1 2 3 4 5 arguments right we’re going to specify our memory usage Das jar server.jar no we gooey right these are all uh right These are all arguments being passed to the Java process so we could build this container and run it just like this and that’s fine but if we wanted to make this more flexible we could take Java and move that under entry point so then Java will run and then these arguments will be Provided to Java now this provides maximum flexibility because people who use our container if they don’t provide any arguments then Java and then all of these arguments will be run by default this is the default command but they can also specify their own arguments to the Java process and override these if they So choose if they need to add additional things onto this command so if I open up a terminal so to help get this point across let’s say I build my container just like this then when I run my container let’s say the images called uh Minecraft and it’s the Latest what would happen is the container would start and it would just run Java and nothing else so then I when I run this container would have to specify the arguments like- jar server.jar right so not really that efficient but it gives me some flexibility I can pass in whatever Commands I want but if I commented out this when the container starts um it’s not going to run Java but it’s going to run this and nothing’s really going to happen now if I have both of them I get the best of both worlds so I build the Container right what’s going to happen is when the container starts it’s going to run Java and then pass in all these arguments to the Java process but what I can also do is I can override this so say I have my container image built and I do Docker run Minecraft latest I can specify these arguments right- jar but I can override them so maybe I want to do um- xmx and specify 2048m instead of the default 1024 M right so that is the flexibility we get when we use entry point and CMD together so enough of my rambling let’s go ahead And actually build this stalker container now and test it out so what we’re going to do is making sure that we are in the same folder or directory that our Docker file is in we’re going to go ahead and run our Docker build- T and we’re going to specify the name of our Container image so this will be Minecraft uh custom let’s do that and we can also specify a tag I’ll do latest and then period dot just meaning this folder or directory that we’re currently in so we’re building the container image so the container image is built so Now if we do a Docker image LS there we go we can see that we have our Custom Image name here and our tag is latest because that’s what we set the tag to so then over here on Docker desktop if we’re using Docker desktop if We go to image we’ll also see our image there and we can hit this run button and we can specify the name of the container as we’ll see it when it’s running so we’ll just call it Minecraft and 25565 and we don’t need to do anything Else and so we’re going to run our container and now when it runs it’s executing the command that we specified to actually start the Minecraft server and if we go into our files here we should be be able to see we have a Minecraft folder that’s the working Directory we set when we built the container and we have our ea. txt with our EA equals true as we expect to see it because we had created that file when we built the container so we’re not putting that responsibility on the users that consume our container Image to accept the EA we’re just doing it for them when we ship the container so now under containers I can see my Minecraft container is running so I’m going to load up the Minecraft client and we can see that we’re using version 1 1203 of Minecraft Server so I’m going to load up the client here so I can test the connection and I need to make sure I’m on the same version as my server which it’s not on this list so I’m going to go to installations and new installation and I’m going to make sure I do 1.2.3 create that and then I will go ahead and choose that hit play multiplayer and we want to go ahead and make sure so we’re connecting on Local Host 25565 we can see that we should be able to join here and Bam we are connected to our Minecraft container so the Equivalent Docker seal I command to run this container image if you’re not using Docker desktop right so I just did a Docker image LS so I can get the name of the container image that I want to use is going to be Docker run and then any arguments right so we’re Going to do- p and this is going to map uh the port on my PC to the listening Port configured that we’ve exposed for the container so I’m just going to do 25565 I’m also going to do- D so the container uh starts in the background I Don’t want it to you know take up my terminal I want to be able to keep using this terminal and then the name of the container image so Minecraft dcom latest and that is all we need to do and then if I do a Docker PS you know My Minecraft container is running and we can see that the command that it’s executing and so that’s the docker uh CLI command so that’s it for this video there are other Docker file instructions as you can see that we did not go over uh just due to time if you are Interested in these I’ll leave a link in the description so you can go ahead and check some of these out there’s some other cool ones in here and you can continue learning I’ll also have a link in the description to a GitHub repository that has the docker files as We built them in this video so you can copy and paste them or use them as a Reference a Video Information
This video, titled ‘How to Create a Minecraft Server Container Image | Create Your Custom Minecraft Image with Docker’, was uploaded by The_Sudo on 2023-12-22 20:27:55. It has garnered 309 views and 16 likes. The duration of the video is 00:34:01 or 2041 seconds.
This video is all about creating your very own custom Minecraft server container image using Docker.
▬▬▬▬▬▬ R E F E R E N C E S AND LINKS 🔗▬▬▬▬▬▬ ► Git repo: https://github.com/TheSudoYT/How-to-build-a-minecraft-container-image ► Dockerfile Documentation: https://docs.docker.com/engine/reference/builder/
▬▬▬▬▬▬ What you’ll learn in 30 Minutes ✅ ▬▬▬▬▬▬ ► How to create a container image using Docker ► How to create a Minecraft container image using existing container images as a base ► How to create a Minecraft container image from scratch ► How to build container images in general
▬▬▬▬▬▬ T I M E S T A M P S ⏰ ▬▬▬▬▬▬ 00:00 – Intro and Overview 01:41 – Getting Setup 02:28 – Example 1 Creating a Minecraft Container From an Existing Image 17:05 – Example 2 Creating a Minecraft Container From Scratch 33:13 – Other Dockerfile Instructions