Update the Dockerfile for readability
- Make the download/verify section more readable - Add JVM_OPTS to CMD - Use ARG EULA during the build - Update build instructions in README
This commit is contained in:
parent
08fc5d16c8
commit
0c19cc1913
32
Dockerfile
32
Dockerfile
@ -1,9 +1,9 @@
|
|||||||
FROM debian:stable
|
FROM debian:stable
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
|
||||||
ENV VERSION=1.20.1
|
ENV VERSION=1.20.1
|
||||||
ENV JVM_OPTS="-Xmx2G -Xms1G"
|
ENV JVM_OPTS="-Xmx2G -Xms1G"
|
||||||
ENV EULA=false
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
ARG EULA=false
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
@ -21,17 +21,21 @@ RUN mkdir /app && \
|
|||||||
|
|
||||||
# Download and verify sha1sum for server.jar
|
# Download and verify sha1sum for server.jar
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json \
|
|
||||||
| jq -r --arg id "$VERSION" '.versions[] | select(.id == $id) | .url' | xargs curl -s \
|
|
||||||
| jq -r '.downloads.server' | tee "/tmp/dl.json" | jq -r '.url' | xargs curl -s -o server.jar \
|
|
||||||
&& sha1sum server.jar | awk '{print $1}' | xargs -I{} sh -c '[ "{}" = "$(jq -r .sha1 /tmp/dl.json)" ] && \
|
|
||||||
(echo "Checksum matches" && rm /tmp/dl.json) || (echo "Checksum failed" && exit 1)' \
|
|
||||||
&& chown minecraft:minecraft server.jar
|
|
||||||
|
|
||||||
USER minecraft
|
USER minecraft
|
||||||
|
RUN set -ux; \
|
||||||
|
# Get server.jar based on $VERSION
|
||||||
|
curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json \
|
||||||
|
| jq -r --arg id "$VERSION" '.versions[] | select(.id == $id) | .url' | xargs curl -s \
|
||||||
|
| jq -r '.downloads.server' | tee "/tmp/dl.json" | jq -r '.url' | xargs curl -s -o server.jar && \
|
||||||
|
java -jar server.jar --initSettings --nogui && \
|
||||||
|
sed -i "s/^eula=.*\$/eula=$EULA/" eula.txt && \
|
||||||
|
# Get SHA1 hash of server.jar and compare
|
||||||
|
SHA1="$(sha1sum server.jar | awk '{print $1}')" && \
|
||||||
|
EXPECTED="$(jq -r .sha1 /tmp/dl.json)"; rm /tmp/dl.json && \
|
||||||
|
if [ ! "$SHA1" = "$EXPECTED" ]; then \
|
||||||
|
echo "[ERROR] SHA1=\"$SHA1\" expected \"$EXPECTED\""; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
EXPOSE 25565
|
EXPOSE 25565
|
||||||
|
CMD ["java", "-jar", "server.jar", "$JVM_OPTS", "--nogui"]
|
||||||
# temp
|
|
||||||
RUN echo 'eula=true' > eula.txt
|
|
||||||
|
|
||||||
CMD ["java", "-jar", "server.jar", "nogui"]
|
|
||||||
|
@ -4,7 +4,9 @@ This Dockerfile sets up a Minecraft server based on Debian stable. WIP.
|
|||||||
|
|
||||||
To test image creation, run:
|
To test image creation, run:
|
||||||
```
|
```
|
||||||
docker build . -t minecraft:vanilla; docker run -d minecraft:vanilla
|
docker build --build-arg EULA=true -t minecraft . && \
|
||||||
|
docker run -d --name minecraft --rm minecraft && \
|
||||||
|
docker logs -f minecraft
|
||||||
```
|
```
|
||||||
|
|
||||||
## Copyright and License
|
## Copyright and License
|
||||||
|
Loading…
Reference in New Issue
Block a user