Skip to content

Docker Minecraft Server Container

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.

  1. Create and save the scripts where they need to go. Refer to the FS layout below.
  2. Download the jar file and save it where it needs to go. Refer to the FS layout below.
  3. Create your dockerfile, and create your container.
  4. Run container to test it
  5. Ensure you can connect to it with the Minecraft client.

DOCKERFILE

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$