diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile index ef686025..6e5cd75d 100644 --- a/minecraft-server/Dockerfile +++ b/minecraft-server/Dockerfile @@ -2,6 +2,7 @@ FROM itzg/ubuntu-openjdk-7 MAINTAINER itzg +RUN apt-get update RUN apt-get install -y wget libmozjs-24-bin imagemagick && apt-get clean RUN update-alternatives --install /usr/bin/js js /usr/bin/js24 100 @@ -26,4 +27,5 @@ ENV UID 1000 ENV MOTD A Minecraft Server Powered by Docker ENV LEVEL world ENV JVM_OPTS -Xmx1024M -Xms1024M +ENV TYPE VANILLA ENV VERSION LATEST diff --git a/minecraft-server/README.md b/minecraft-server/README.md index e9e88221..2da52694 100644 --- a/minecraft-server/README.md +++ b/minecraft-server/README.md @@ -56,7 +56,7 @@ replacing 1000 with a UID that is present on the host. Here is one way to find the UID given a username: grep some_host_user /etc/passwd|cut -d: -f3 - + ## Versions To use a different Minecraft version, pass the `VERSION` environment variable, which can have the value @@ -73,6 +73,26 @@ or a specific version: docker run -d -e VERSION=1.7.9 ... +## Running a Forge Server + +By default the container will run the selected "vanilla" (aka official) Minecraft server, but +you can also choose to run the `LATEST` or a specific version of a [Forge server](http://www.minecraftforge.net/wiki/). +Enable Forge server mode, by adding a `-e TYPE=FORGE` to your command-line, such as + + $ mkdir forge + $ docker run -d -v $(pwd)/forge:/data -e TYPE=FORGE -e VERSION=1.7.10 \ + -p 25565:25565 -e EULA=TRUE itzg/minecraft + +**NOTE**: You *must* use a host-attached volume of the container's `/data` in order +to access the `mods` directory. [Docker 1.6 has a scheduled feature](https://github.com/docker/docker/pull/10198) to extend `docker cp` to enable +copying files *into* a container -- until then attach the `/data` volume. + +If your container is running when adding mods, you'll need to restart it to pick those +up: + + docker stop $ID + docker start $ID + ## Server configuration ### Op/Administrator Players diff --git a/minecraft-server/start-minecraft.sh b/minecraft-server/start-minecraft.sh index 568a7d5b..1c619ad8 100755 --- a/minecraft-server/start-minecraft.sh +++ b/minecraft-server/start-minecraft.sh @@ -15,22 +15,60 @@ if [ ! -e /data/eula.txt ]; then fi fi +echo "Checking version information." case $VERSION in LATEST) - export VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.release)'` - ;; - + VANILLA_VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.release)'` + ;; SNAPSHOT) - export VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.snapshot)'` - ;; + VANILLA_VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.snapshot)'` + ;; + *) + VANILLA_VERSION=$VERSION + ;; esac cd /data -if [ ! -e minecraft_server.$VERSION.jar ]; then - echo "Downloading minecraft_server.$VERSION.jar ..." - wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VERSION/minecraft_server.$VERSION.jar -fi +echo "Checking minecraft / forge type information." +case $TYPE in + VANILLA) + SERVER="minecraft_server.$VANILLA_VERSION.jar" + + if [ ! -e $SERVER ]; then + echo "Downloading $SERVER ..." + wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VANILLA_VERSION/$SERVER + fi + ;; + + FORGE) + # norm := the official Minecraft version as Forge is tracking it. dropped the third part starting with 1.8 + case $VANILLA_VERSION in + 1.7.*) + echo OLDER + norm=$VANILLA_VERSION + ;; + + *) + norm=`echo $VANILLA_VERSION | sed 's/^\([0-9]\+\.[0-9]\+\).*/\1/'` + ;; + esac + + FORGE_VERSION=`wget -O - http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json | jsawk -n "out(this.promos['$norm-latest'])"` + + normForgeVersion="$norm-$FORGE_VERSION" + FORGE_INSTALLER="forge-$normForgeVersion-installer.jar" + SERVER="forge-$normForgeVersion-universal.jar" + + if [ ! -e $SERVER ]; then + echo "Downloading $FORGE_INSTALLER ..." + wget -q http://files.minecraftforge.net/maven/net/minecraftforge/forge/$normForgeVersion/$FORGE_INSTALLER + echo "Installing $SERVER" + java -jar $FORGE_INSTALLER --installServer + fi + ;; + +esac if [ ! -e server.properties ]; then cp /tmp/server.properties . @@ -62,7 +100,7 @@ if [ ! -e server.properties ]; then exit 1 ;; esac - + sed -i "/gamemode\s*=/ c gamemode=$MODE" /data/server.properties fi fi @@ -85,5 +123,4 @@ if [ -n "$ICON" -a ! -e server-icon.png ]; then fi fi -exec java $JVM_OPTS -jar minecraft_server.$VERSION.jar - +exec java $JVM_OPTS -jar $SERVER