Skip to content

Updating install script and Dockerfile to use version ARG #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM cgr.dev/chainguard/jre:latest-dev@sha256:75727a660ffd6e3b8e076e47e38c192da3da3f9dd629f5245af2982270c5eb2c

ARG VERSION="latest"
USER root
RUN apk update && apk add curl libudev jq
RUN adduser --system minecraft
WORKDIR /usr/share/minecraft

COPY build-config.sh server-install.sh /usr/share/minecraft/
RUN chmod +x /usr/share/minecraft/build-config.sh /usr/share/minecraft/server-install.sh
RUN /usr/share/minecraft/server-install.sh
RUN /usr/share/minecraft/server-install.sh ${VERSION}
RUN chown -R minecraft /usr/share/minecraft
USER minecraft

Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GuardCraft is a containerized Minecraft (Java) server built on top of the [Java

## Using the Image

The following command will run an ephemeral Minecraft Java server with default settings. This will create a world in survival mode with difficulty set to "normal", and a random world seed. The port redirection will make the server available at `localhost:25565` in the host machine.
The following command will run an ephemeral Minecraft Java server with default settings. This will create a world in survival mode with difficulty set to "normal", and a random world seed, using the latest version of the Minecraft server. The port redirection will make the server available at `localhost:25565` in the host machine.

```shell
docker run --rm -p 25565:25565 ghcr.io/chainguard-dev/guardcraft-server:latest
Expand Down Expand Up @@ -42,7 +42,11 @@ Starting net.minecraft.server.Main
[13:06:54] [Server thread/INFO]: Done (3.933s)! For help, type "help"
```

You can connect to the server using a Minecraft Java client on the same local network. Add a new server using the host machine's local IP address and port `25565` (the default port). You can also use the `localhost` address if you're running the server on the same machine as the client.
You can connect to the server using a Minecraft Java client on the same local network. Please note the client must be running the same version of the server software (in this case, `1.21.5 Pre-Release 3`) - you may need to select the appropriate version in the Minecraft launcher software.

To specify which version of the server you want to use, you'll need to [build the image from source](#building-from-source) and provide a build time argument to specify which version you want to install.

Add a new server using the host machine's local IP address and port `25565` (the default port). You can also use the `localhost` address if you're running the server on the same machine as the client.

> Find your local IP address on Linux systems: `ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p'`

Expand Down Expand Up @@ -125,6 +129,11 @@ You can also build this image from source in your local environment. Clone the r
```shell
docker build -t guardcraft-java .
```
If you want to specify the version of the Minecraft server, you can pass the `VERSION` argument at build time, like this:

```shell
docker build --build-arg VERSION=1.21.4 . -t guardcraft-java
```

Use the following command to run the image in your local environment:

Expand Down
2 changes: 1 addition & 1 deletion server-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Usage: server-download.sh [version]
# If no version is provided, the latest version is used

if [ -n "$1" ]; then
if [ -n "$1" ] && [ "$1" != "latest" ]; then
version=$1
else
version=$(curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json | jq -r '.versions | first | .id')
Expand Down