This guide has been written as a good reference to getting a Minecraft server running within a Docker container.
- READ all the following documentation, so you have a good frame of reference for what is needed (mostly copy/paste). You will need to determine if the scripts are sufficient for your situation and setup and then modify them slightly to fit it. Namely the volume declaration in the container start script.
- I presume that you know what Docker, Linux, and bash are, and have a VPS/server to host things.
- This guide is not limited to being run on EL7 host, but the container is without heavy modification to the dockerfile. Hack away if you can make SuSE, Debian, Ubuntu, or Slackware work instead. The core guts should be rather straightforward. I am a Red Hat guy, and actually use RHEL rather than CentOS. But for easier copying/pasting exchanged rhel:latest with centos:latest in the dockerfile.
- This can be (and I have numerous times) used this to make other Minecraft variant server containers. I have used this with FTB and ATLauncher. Very compatible. Create a new volume, modify docker container start script accordingly, and copy & modify the minecraft launch script accordingly.
Lastly is the order in which things need to be done.
- Create and save the scripts where they need to go. Refer to the FS layout below.
- Download the jar file and save it where it needs to go. Refer to the FS layout below.
- Create your dockerfile, and create your container.
- Run container to test it
- Ensure you can connect to it with the Minecraft client.
We are going to keep this lean, only adding in tmux, vim, wget, and curl for quality of life issues.
FROM centos:latest RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm deltarpm RUN yum -y update RUN yum -y install tmux \ java-1.8.0-openjdk \ vim \ wget \ curl \ RUN yum -y clean all RUN useradd minecraft USER minecraft ENV HOME /home/minecraft CMD /bin/bash ENTRYPOINT ["/bin/bash","/home/minecraft/start-minecraft.sh"]
Docker launch script
We will need a script to launch this container. I use volumes to make life easier, both retaining world data, but also facilitating some (albeit not full) automation.
#!/bin/bash docker run -ti --rm\ --name=minecraft \ -p=25565:25565 \ -m=1g \ -v=/storage/docker/minecraft:/home/minecraft:z \ minecraft:latest
Minecraft start script
This is the script inside the container that will fire up Minecraft. You want this in the volume's root that you pass in. Since in this example we have passed /storage/docker/minecraft in as /home/minecraft, we want this script at the /storage/docker/minecraft location.
The following script also has a line for determining the newest filename, so when you update, you can wget/curl the correct file in and restart the container.
#!/bin/bash cd /home/minecraft FILENAME=`ls -t minecraft_server* | head -1` java -server -Xmx256M -jar $FILENAME nogui
Managing the container
Run this to enter the container to manage it:
docker exec -it minecraft bash
Simple volume file structure
Sanitized ls of my volume as the container sees it:
$ docker exec -it minecraft bash bash-4.2$ cd /home/minecraft/ bash-4.2$ ls -1 banned-ips.json banned-players.json crash-reports eula.txt logs minecraft_server.1.11.2.jar minecraft_server.1.12.1.jar minecraft_server.1.12.jar ops.json plugins server.properties start-minecraft.sh usercache.json whitelist.json bash-4.2$