Skip to content

Instantly share code, notes, and snippets.

@justincjahn
Last active July 24, 2016 09:20
Show Gist options
  • Save justincjahn/660b744d8ee7ba275aa4 to your computer and use it in GitHub Desktop.
Save justincjahn/660b744d8ee7ba275aa4 to your computer and use it in GitHub Desktop.
Docker Minecraft Server
FROM centos:latest
MAINTAINER jjahn
# UPDATE
RUN yum -y update
# Install Java and GNU Build Tools
RUN yum -y install java-1.8.0-openjdk
RUN yum -y groupinstall "Development Tools"
# Default minecraft port
EXPOSE 25565
# Add the start script to the container
ADD start.sh /start
RUN chmod a+x /start
# Where the minecraft data will be stored
VOLUME ['/data']
WORKDIR /data
# The command run when the contianer starts
CMD /start
# Environment variables used by the start command
ENV MOTD Jahn Digital Minecraft Server
ENV LEVEL world
ENV JVM_OPTS -Xmx1024M -Xms1024M
ENV VERSION 1.7.10
ENV EULA true
#!/bin/sh
cd /data
if [ ! -e minecraft_server.jar ]; then
>&2 echo "Unable to locate minecraft_server.jar. Please place it in the path you mounted to /data and try again."
exit 1
fi
if [ ! -e server.properties ]; then
cp /tmp/server.properties .
fi
if [ -n "$MOTD" ]; then
sed -i "/motd\s*=/ c motd=$MOTD" /data/server.properties
fi
if [ -n "$LEVEL" ]; then
sed -i "/level-name\s*=/ c level-name=$LEVEL" /data/server.properties
fi
if [ -n "$OPS" ]; then
echo $OPS | tr , '\n' > ops.txt
fi
if [ ! -e /data/eula.txt ]; then
if [ "$EULA" != "" ]; then
echo "# Generated via Docker on $(date)" > eula.txt
echo "eula=$EULA" >> eula.txt
else
echo ""
echo "Please accept the Minecraft EULA at"
echo " https://account.mojang.com/documents/minecraft_eula"
echo "by adding the following immediately after 'docker run':"
echo " -e EULA=TRUE"
echo ""
exit 1
fi
fi
java $JVM_OPTS -jar minecraft_server.jar nogui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment