Minecraft Server Docker Image

Dockerfile

Create a Dockerfile for the minecraft server image with the following:

FROM ubuntu:xenial
MAINTAINER Richard Meyer <meyerrj@rayonnant.net>
ENV MINECRAFT_VERSION 1.11.2
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update && apt-get -y upgrade && apt-get install --no-install-recommends -y -q \
    software-properties-common \
    && apt-add-repository -y ppa:webupd8team/java \
    && apt-get -y update \
    && echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections \
    && echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections \
    && apt-get install --no-install-recommends -y -q curl oracle-java8-installer oracle-java8-set-default \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean
    
COPY ./start-server.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/start-server.sh && mkdir -p /data
EXPOSE 25565
EXPOSE 25575
VOLUME ["/data"]
WORKDIR /data
CMD ["start-server.sh"]

Startup Script

Create the start-server.sh file with the following content.

#!/bin/bash
if [ ! -f /data/minecraft_server.jar ]
then
    echo "Downloading: minecraft_server.${MINECRAFT_VERSION}.jar"
    curl "https://s3.amazonaws.com/Minecraft.Download/versions/${MINECRAFT_VERSION}/minecraft_server.${MINECRAFT_VERSION}.jar" -o /data/minecraft_server.jar
fi
if [ ! -f /data/eula.txt ]
then
    echo "eula=true" > /data/eula.txt
fi
cd /data/
java -Xmx2048M -Xms2048M -jar minecraft_server.jar nogui

Building the Image

sudo docker build --no-cache --pull -t meyerrj/minecraft-server:latest .

Starting the Minecraft Server Instance

sudo docker run --name minecraft-server --restart=always -d \
    -p 25565:25565 -p 25575:25575 \
    -v /mnt/data/minecraft:/data:rw \
    meyerrj/minecraft-server:latest

First Run

If you are running the server for the first time, you can stop the instance, change the configuration files as necessary, and simply restart the instance.

Server Updates

When a new version of the Minecraft server is released, you can do the following:

Stop and remove the current instance:

  • sudo docker stop minecraft-server
  • sudo docker rm minecraft-server

Delete the minecraft_server.jar file

  • sudo rm /mnt/data/minecraft/minecraft_server.jar

Adjust MINECRAFT_VERSION environment variable to match the appropriate version number, and start the docker instance

  sudo docker run --name minecraft-server --restart=always -d \
  -e MINECRAFT_VERSION='11.1.2' \
  -p 25565:25565 -p 25575:25575 \
  -v /mnt/data/minecraft:/data:rw \
  meyerrj/minecraft-server:latest

Another option would be to change the version in the Dockerfile and rebuild the image, and run it as before.

Networking Notes

  • TCP Port 25565 is the standard game server port
  • TCP Port 25575 is for RCON and should be exposed only to trusted networks
Show Comments