In this tutorial, we will show you how to run a Minecraft Java Edition Server using Docker.
Minecraft is one of the most popular games, known for its fantastic sandbox experience. It is also a game that can be even better when played with other people.
Hosting your own Minecraft Java Edition server can be a cost-effective way to play your world anywhere and let others join the fun. All you need for this tutorial is a computer you can install Docker and a decent internet connection to which you can open a couple of ports.
Docker is a great way to run a Minecraft Java Edition server, as you can keep it somewhat isolated from the rest of your system. Using Docker can also make managing the server a breeze, with updates as simple as restarting the container.
As Mojang does not provide its own container for the Minecraft Java Edition server, we will be using one provided by Itzg. This container is the go-to solution for running the Minecraft server using Docker.
The following guide is written with a focus on Linux-based operating systems. We highly recommend Ubuntu as a great starting point if you are unfamiliar with a Linux operating system.
Running a Minecraft Java Edition Server using Docker
These sections will walk you through getting a Minecraft Java Edition Server running through a Docker container.
You should hopefully find these steps relatively easy to follow, even for a beginner. All you need to know is how to open the terminal. We explain what each command does and how you can configure the server for your own needs.
If there is anywhere in this guide that you feel like needs more explaining, please drop a comment below.
Installing Docker to run the Minecraft Server
1. To be able to run a Minecraft server using Docker, we will need to install it.
If you already have Docker installed on your system, skip straight to step 4. Alternatively, run the command below to run the Docker install script.
curl -sSL https://get.docker.com | sh
2. After installing Docker, you will want to make it so your current user can access and use it.
To do this, you must add your user to the “
docker” group using the command below.
sudo usermod -aG docker $USER
3. Group changes don’t take effect until you log out of your current user. If you are using SSH, this is as simple as running the following command.
However, on desktop you may have to restart your device by using the command below.
Creating a Directory to Store the Server and Docker Compose File
4. With Docker installed, we can now do some other preparatory work so that we can use it to run a Minecraft server.
Our first task is creating directory to store our Docker Minecraft server by using the mkdir command.
sudo mkdir -p /opt/stacks/minecraftjava
Using the “
-p” option, the command will create all missing directories in the path.
5. After creating the directory, you must change to it by utilizing the cd command.
We will write the Docker Compose File to start the Minecraft Server within this directory. It is also where the server will store your world data and other files.
Writing a Docker Compose file for the Minecraft Java Edition Server
6. Now that everything is set up, we can write the Docker Compose file to manage the Minecraft server.
You can begin writing this file by running the command below within the terminal.
sudo nano compose.yaml
We are using the nano text editor as it is a relatively simple terminal-based text editor.
Filling out the Compose File
7. Within this Compose file, you will want to enter the following lines. These lines tell Docker we want to use the Minecraft Server Image.
We also use this file to define variables that the Docker image will use to set up the server. We are only touching on a few of these options, but you will find that this container is super configurable.
- TYPE: Using this option, you can choose what type of Minecraft Java Edition server you want to use.
This guide focuses on setting up a Vanilla server, but you can set up alternatives like PaperMC, SpigotMC, and even Minecraft Forge.
- VERSION: The next environment variable we define specifies the Minecraft version the Docker Container should set up.
We set this to “
LATEST” so that it will always download the latest version.
- EULA: This option you should always remain the same. It is saying that you agree to the Minecraft end-user license agreement.
You must agree to this document to run a Minecraft server on any device.
- MEMORY: The memory option allows you to set the amount of RAM your Minecraft server can consume.
A good starting value for this option is “
2G“, which will allocate 2 gigabytes of RAM to your server.
Ensure you replace “
<MEMORY>” with the memory you want to be allocated to the server.
- RCON_PASSWORD: The last thing you need to set is the RCON Password. This password will allow you to control your Docker Minecraft server remotely.
<PASSWORD>” with a password of your choosing. Ensure you make this something secure, as someone could abuse it.
# attach the relative directory 'data' to the container's /data path
Saving the Docker Compose File for Minecraft
8. After writing out the Compose file, save and quit by pressing CTRL + X, Y, and then the ENTER key.
Starting the Server
9. At this point, we can start up the Minecraft Java Edition Docker Server by running the command below.
During start-up, Docker will download the latest Minecraft container and then start it using your environment variables.
docker compose up -d
By utilizing the “
-d” option, Docker will start up the Minecraft server and detach from the terminal. This allows the server to continue to run even after the current session closes.
10. Once the Minecraft container is running, you can now connect to it.
To connect to your server, you will need to know the local IP address of your device. You can get this IP by using the hostname command in the terminal.
Below, you can see how this command returned our device’s local IP address.
Connecting to your Minecraft Server
11. To access your new Docker Minecraft server, you must load up the Minecraft client.
Once you have the client open, click the “
12. On the multiplayer screen, there is a chance your server is automatically detected.
However, you can click the “
Direct Connection” button if you have the IP address.
13. Now, type the IP address of your Minecraft server into the provided textbox (1.).
After typing in your address, click the “
Join Server” button to connect (2.).
14. You should now hopefully be playing on your Docker Minecraft server.
If you want outside access, you can now port forward port
25565 to your server, or you can use a service like Tailscale.
Sending Commands to the Docker Minecraft Java Edition Server
15. Next, you will want to know how to send commands to your Minecraft Docker server.
The best way to do this is to utilize the “
rcon-cli” tool that is included within the container.
You can open this command line tool using the following command while in the same directory in which you wrote the “
compose.yaml” file earlier.
docker compose exec -i mc rcon-cli
16. You can now run any Minecraft commands within the terminal.
For example, if you wanted to “
OP” a player, you would use the following command.
17. Once you are done using the command line tool, you can press CTRL + C to exit.
Managing your Minecraft Docker Server
In this section, we will quickly show you a couple of ways that you can manage your Minecraft Docker Server.
In particular, we will show you how to shut the server down, restart it, and update it.
You must run all the commands in the following sections within the same directory you wrote the compose file. If you strictly followed our guide, you should be in the directory “
Shutting Down your Minecraft Java Server
Shutting down your Docker-based Minecraft Java server is super simple.
You only need to run the following command, and Docker will safely shut down the container.
docker compose down
Restarting your Server
Restarting is also incredibly straightforward, like shutting down your server, and can be done with the command below.
This command is helpful to know, as the image we are using will automatically update to your chosen Minecraft server when it starts up.
docker compose restart
Updating your Minecraft Docker Server Container
Updating the base image you use for your Minecraft Docker server is quite simple, as you will soon see. All we need to do is tell Docker to re-pull the image and then tell it to start.
You don’t actually need to update the image to update Minecraft, but if something breaks, there’s a chance a new image may fix the issues you are having. You can see changes made to the image by exploring their releases page.
1. To update the Minecraft Docker image, you will want to use the following command.
This command uses Docker to re-pull the images of all containers specified within the compose file.
docker compose pull
2. Docker won’t automatically restart the container to use the new image, we must do this ourselves.
Luckily, all we need to do to load the new image is to use the following command. If a new image is available, Docker will move over to that when it tries to start the Minecraft server.
docker compose up -d
Viewing the Logs of your Minecraft Docker Server
Docker also makes viewing the logs of your Minecraft server an easy process.
You can view the logs using the command below within the terminal. By including the “
-f” option, the log will automatically update as new events are added.
docker compose logs -f
Once you are finished reading through your logs, you can quit by pressing CTRL+ C.
Hopefully, you will now have a Minecraft Java Edition server running through a Docker container.
We achieved this setup thanks to the container from Itzg and a handy Docker compose file that makes setting and running the server a breeze.
Please feel free to comment below if you have any questions or concerns with your Minecraft Docker setup.
If you found this tutorial to be helpful, we recommend checking out our many other guides.