Creating a Java Minecraft Server using Docker

How to Setup Minecraft on Docker

Minecraft is one of the most popular games of all time and this means one thing: Kids want their own server. Lucky for us most of the hard work in running and maintaining the server has already been done using itzg/docker-minecraft-server.

The setup is well documented however the most important step is making sure the data is saved. By default Docker will store the files in the container, but you may upgrade, delete, migrate, or modify the container and potentially lose the saved world data, which is very important to the players who worked no doubt countless hours to build. Passing the -v FOLDER_NAME:/data will use the folder outside of the container to store this data so it is readily available for copying and backups.

To run the container in detached mode, which sets it to run in the background, open a terminal session on the system running Docker:

docker run -d -it --name mc-server -v $HOME/minecraft-server:/data -p 25565:25565 -e EULA=TRUE -e MEMORY=2G itzg/minecraft-server

After running the server there may be a few different network settings: the server firewall and the router firewall.

If the server is running Ubuntu use ufw to allow port 25565 to listen on tcp:

sudo ufw allow 25565/tcp

Most routers include “port forwarding” functionality. Log in to the router’s interface and forward port 25565 with protocol tcp to the system which is running Docker’s IP address (usually like or

Migrating Data from an Older Container

If an older or different Docker container was previously setup it is likely the world data is still under /data. To copy this outside of the container:

docker ps -A # Get the ID of the container like 0da16bd575f7
docker run --rm --volumes-from 0da16bd575f7 -v $HOME/minecraft:/new alpine cp -avT /data /new

This will result in $HOME/minecraft now having the world data from the previous container. At this point it is a good idea to setup backups using itzg/docker-mc-backup