Running Minecraft Sever in Docker
What is Docker?
Docker is a utility that allows you to run applications in a virtualized environment conveniently. This makes your system as a whole more secure, because if an attacker gets into one container, it is harder to infect the whole system. Another big advantage is that when that application crashes, you can simply restart the whole stack running that application. That restarts almost anything that could have crashed and be causing issues without effecting the rest of your server.
Setting up Docker
If you are using a Linux server docker will almost certainly be in your standard repository. On a Debian or Ubuntu server you can simply run sudo apt install docker
. After you install it don’t forget to start and enable docker with sudo systemctl enable docker && sudo systemctl start docker
.
If you have extra resources and want a better docker user experience on your server you can set up Portainer.
Using Docker Compose
To use docker compose you first make a folder for the container. You can run mkdir minecraft-server
. You then change into that directory with cd minecraft-server
. Now you can make a docker compose file. You will need to use an editor for that. My favorite command line editor is neovim, but nano is good for people unfamiliar with vim.
You can start editing the docker-compose.yml
. Then you start that up with docker compose up -d
.
Setting Up Minecraft Java
If you want to quickly set up a temporary minecraft server you can very simply use docker run -d -it -p 25565:25565 -e EULA=TRUE itzg/minecraft-server
. This works well for a quick setup, but if you want a more permanent solution you can use docker compose.
You will want to use your own docker-compose file, but this is mine as a jumping off point.
version: "3.8"
services:
mc:
image: itzg/minecraft-server
tty: true
stdin_open: true
ports:
- "25565:25565" # default minecraft port
restart: always # automatic restart when it crashes
environment:
EULA: "TRUE"
VERSION: "1.16.4" # using 1.16.4 because that is my favorite version
JAVA_VERSION: "java8-multiarch" # java version required for 1.16.4
SERVER_NAME: "Server"
PORT: 25565 # default minecraft port
volumes:
- /home/server/minecraft-world:/data # saving world data to an accessible folder
There are many configuration options and you can find them all in the documentation.
After you set this all up make sure you port forward if you need to do that, and you should be able to access the server on <server-ip>:25565.
Setting Up Minecraft Bedrock
The process to setting up a bedrock server is very similar. If you want a temporary server you can use docker run -d -it -e EULA=TRUE -p 19132:19132/udp
. For more permanent setups docker compose is ideal.
You will want to use your own docker-compose file, but this is mine as a jumping off point.
services:
mc:
image: itzg/minecraft-bedrock-server
tty: true
stdin_open: true
ports:
- 19132:19132/udp # default port
restart: always # automatic restart when it crashes
environment:
EULA: "TRUE"
VERSION: "LATEST"
SERVER_NAME: "Server" # server name
ENABLE_CHEATS: "TRUE" # allows tp etc
volumes:
- /home/jenny/bedrock_minecraft_world:/data # puts world data in accessible folder
You can find other configuration options in the documentation. You will also need to forward ports if you are on a home router.
Using the Console
To properly manage a minecraft server you need to occasionally use the console. The easiest way to do that is to simply run docker attach minecraft-server
. Then you can type commands in.
The logs for the server will be stored in the docker logs.
Alternatives
If you are going to be hosting many minecraft servers and want a more user friendly UI to do that, I would recommend using pterodactyl. It is harder to set up and has more overhead than this method, but it makes managing servers much easier.
You could also always run a minecraft server the old fashioned way.