-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Terence Westphal
committed
Jun 5, 2017
0 parents
commit 039b12b
Showing
11 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
- docker | ||
|
||
install: | ||
- docker build -t minecraft . | ||
- docker run -d -p 25565:25565 --name minecraft minecraft | ||
|
||
script: | ||
- sleep 10 | ||
- docker ps | grep -q minecraft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM openjdk:alpine | ||
|
||
LABEL maintainer "Terence Westphal" | ||
|
||
# Use default value if the build argument is not set | ||
ARG VERSION=1.11.2 | ||
|
||
ENV MC_VERSION=${VERSION} | ||
ENV PACKAGE="/opt/minecraft" | ||
ENV JAR="minecraft_server.${MC_VERSION}.jar" | ||
ENV JAR_OPT="nogui" | ||
ENV WORKDIR="/srv/minecraft" | ||
ENV PATH="${PACKAGE}/scripts:$PATH" | ||
|
||
# Update the system | ||
RUN apk upgrade --no-cache --purge -v | ||
|
||
# Download Minecraft Server | ||
ADD https://s3.amazonaws.com/Minecraft.Download/versions/${MC_VERSION}/${JAR} ${PACKAGE}/${JAR} | ||
|
||
# Add package content | ||
ADD ./defaults/* ${PACKAGE}/defaults/ | ||
ADD ./scripts/* ${PACKAGE}/scripts/ | ||
|
||
# Serve the content from the WORKDIR | ||
WORKDIR ${WORKDIR} | ||
|
||
# Expose the container's WORKDIR | ||
VOLUME ${WORKDIR} | ||
|
||
# Expose the container's network port | ||
EXPOSE 25565 | ||
|
||
# Start the Minecraft server | ||
ENTRYPOINT ["start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Terence Westphal | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[![Build Status](https://travis-ci.org/terencewestphal/docker-minecraft.svg?branch=master)](https://travis-ci.org/terencewestphal/docker-minecraft) [![Docker Build Statu](https://img.shields.io/docker/build/terencewestphal/minecraft.svg)](https://hub.docker.com/r/terencewestphal/minecraft/builds/) [![Docker Stars](https://img.shields.io/docker/stars/terencewestphal/minecraft.svg)]() [![Docker Pulls](https://img.shields.io/docker/pulls/terencewestphal/minecraft.svg)](https://hub.docker.com/r/terencewestphal/minecraft/) | ||
|
||
[![Minecraft](https://github.com/terencewestphal/docker-minecraft/blob/master/logo.png?raw=true)](https://minecraft.net/) | ||
|
||
# Minecraft Server (Vanilla) | ||
|
||
**The vanilla Minecraft server in a Docker container** | ||
|
||
- Minimalistic and simple to configure. | ||
- Works out-of-the-box. Defaults are provided if no volume is mounted. | ||
- Based on the [Official OpenJDK Alpine](https://hub.docker.com/_/openjdk/) image. | ||
|
||
## Supported tags and Dockerfile | ||
|
||
- `1.11.2`, `latest` ([Dockerfile](https://raw.githubusercontent.com/terencewestphal/docker-minecraft/1.11.2/Dockerfile)) | ||
|
||
|
||
### Pull | ||
|
||
Get the latest version: | ||
``` | ||
docker pull terencewestphal/minecraft:latest | ||
``` | ||
|
||
Get a specific version: | ||
``` | ||
docker pull terencewestphal/minecraft:1.11.2 | ||
``` | ||
|
||
### Build | ||
|
||
Build the latest Minecraft version and tag the image: | ||
``` | ||
docker build -t minecraft . | ||
``` | ||
|
||
Optional: Build with a specific Minecraft version: | ||
``` | ||
docker build --build-arg VERSION=1.11.2 -t minecraft . | ||
``` | ||
|
||
### Run | ||
|
||
Run with default settings: | ||
``` | ||
docker run -d -p 25565:25565 --name minecraft terencewestphal/minecraft | ||
``` | ||
|
||
Run with volume mounted: | ||
``` | ||
docker run -d -p 25565:25565 -v $PWD/defaults:/srv/minecraft --name minecraft terencewestphal/minecraft | ||
``` | ||
|
||
### Interactive Mode | ||
|
||
Attach an interactive console in order to use the Minecraft server commands: | ||
``` | ||
docker attach minecraft | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -eu | ||
|
||
accept_eula() { | ||
fileExists "${WORKDIR}/eula.txt" || echo "eula=true" > "${WORKDIR}/eula.txt" | ||
} | ||
|
||
available_memory() { | ||
free -m | grep Mem | awk '{ print $4 }' | ||
} | ||
|
||
copy() { | ||
local src=$1 | ||
local dest=$2 | ||
cp -Rf "${src}" "${dest}" >/dev/null 2>&1 || error "Failed to copy ${src}" | ||
} | ||
|
||
check_defaults() { | ||
local item | ||
for item in ${PACKAGE}/defaults/*.json; do | ||
local file="${item##*/}" | ||
fileExists "${WORKDIR}/${file}" || copy "${PACKAGE}/defaults/${file}" "${WORKDIR}/${file}" | ||
done; | ||
} | ||
|
||
error() { | ||
sleep 0.1 | ||
local message=$@ | ||
echo "[ERROR] ${message}" 1>&2 && exit 1 | ||
} | ||
|
||
fileExists() { | ||
local file=$1 | ||
[[ -f "${file}" ]] || return 1 | ||
} | ||
|
||
start_server() { | ||
local ram=$(available_memory) | ||
local jvm_opt="-Xms256M -Xmx${ram}M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts" | ||
local jar_opt="${JAR_OPT}" | ||
local server="${PACKAGE}/${JAR}" | ||
fileExists "${server}" || error "Failed to locate ${server}" | ||
|
||
# Run the server as PID 1 | ||
exec java ${jvm_opt} -jar ${server} ${jar_opt} | ||
} | ||
|
||
check_defaults | ||
accept_eula | ||
start_server |