# Getting started

This guide builds the Sculkworm container locally, starts two throwaway Minecraft Java Edition status backends using `minecraft-protocol`, writes a routes file, runs Sculkworm, pings both hostnames, reloads routes with `SIGHUP`, inspects the structured logs, and shuts everything down.

Every command runs in a terminal on the host. Each command block is followed by the output you see. Values in angle brackets, like `<container id>`, or ephemeral client port numbers change on every run.

The walkthrough publishes the relay on `127.0.0.1:25595` so it does not collide with any local Minecraft server on port `25565`. In production, publish `-p 25565:25565` and drop `--add-host`.

## Prerequisites

- Docker Engine
- Node.js 22.18 or later and `npm` (for the two throwaway backends and the status ping client)

## 1. Get the container image (or standalone binaries)

Pull a published relay image from `ghcr.io/yellowumbrelladev/sculkworm` (for example `:nightly` or an exact `<version>` tag from [Releases](https://github.com/YellowUmbrellaDev/sculk.network/releases)) and tag it locally as `sculkworm` for the rest of this guide:

```sh
docker pull ghcr.io/yellowumbrelladev/sculkworm:nightly
docker tag ghcr.io/yellowumbrelladev/sculkworm:nightly sculkworm
```

Or build the image locally from `crates/sculkworm` (or pass `crates/sculkworm` from the repository root):

```sh
docker build -t sculkworm crates/sculkworm
```

The build compiles a static Linux musl binary and packages it into a non-root distroless image. It finishes with:

```text
 => => naming to docker.io/library/sculkworm:latest
```

To run `sculkworm`, `sculkworm-agent`, or `sculkworm-connect` directly without Docker, download a release archive and verify it against `SHA256SUMS` as shown in [Installing binaries from a release](https://docs.sculk.network/nightly/sculkworm/deploy.md#installing-binaries-from-a-release).

## 2. Start two local Minecraft status backends

Create a working directory and install `minecraft-protocol` pinned to `1.68.0`:

```sh
mkdir -p sculkworm-demo/config
cd sculkworm-demo
cat > package.json <<'EOF'
{
  "name": "sculkworm-demo",
  "private": true,
  "type": "module",
  "dependencies": {
    "minecraft-protocol": "1.68.0"
  }
}
EOF
npm install --no-audit --no-fund
```

Save `backends.mjs` to start two offline-mode Minecraft 1.21.4 status responders on ports `25581` and `25582` with distinct MOTDs:

```sh
cat > backends.mjs <<'EOF'
import mc from 'minecraft-protocol';

const servers = [
  { port: 25581, motd: 'Survival backend' },
  { port: 25582, motd: 'Creative backend' },
];

for (const { port, motd } of servers) {
  const server = mc.createServer({
    'online-mode': false,
    host: '0.0.0.0',
    port,
    version: '1.21.4',
    motd,
  });
  server.on('listening', () => {
    console.log(`listening on 0.0.0.0:${port} (${motd})`);
  });
}
EOF
```

Start both backends in the background and confirm they are listening:

```sh
node backends.mjs &
BACKENDS_PID=$!
```

```text
listening on 0.0.0.0:25581 (Survival backend)
listening on 0.0.0.0:25582 (Creative backend)
```

## 3. Write the routes file and start Sculkworm

Write `config/routes.json` mapping two hostnames to the two local backends via `host.docker.internal`:

```sh
cat > config/routes.json <<'EOF'
{
  "routes": {
    "survival.play.example": "host.docker.internal:25581",
    "creative.play.example": "host.docker.internal:25582"
  }
}
EOF
```

Start the Sculkworm container with `./config` mounted read-only at `/etc/sculkworm`. Mounting the directory (rather than the single file) lets atomic file replacements become visible inside the container on `SIGHUP`:

```sh
docker run -d --name sculkworm \
  --add-host=host.docker.internal:host-gateway \
  -p 127.0.0.1:25595:25565 \
  -v "$PWD/config:/etc/sculkworm:ro" \
  sculkworm
```

```text
<container id>
```

Check the startup log:

```sh
docker logs sculkworm
```

```text
level=info event=listening addr=0.0.0.0:25565 routes=2
```

## 4. Ping both hostnames and an unknown hostname

Save `ping.mjs`, which connects to `127.0.0.1:25595` while sending the requested hostname in the Minecraft 1.21.4 Handshake packet:

```sh
cat > ping.mjs <<'EOF'
import net from 'node:net';
import mc from 'minecraft-protocol';

const [, , serverHost, relayPort = '25595'] = process.argv;
const status = await mc.ping({
  host: serverHost,
  port: Number(relayPort),
  version: '1.21.4',
  connect: (client) => {
    const socket = net.connect(Number(relayPort), '127.0.0.1');
    client.setSocket(socket);
    client.emit('connect');
  },
});
console.log(JSON.stringify({ host: serverHost, version: status.version.name, motd: status.description.text }));
EOF
```

Ping `survival.play.example`:

```sh
node ping.mjs survival.play.example 25595
```

```json
{"host":"survival.play.example","version":"1.21.4","motd":"Survival backend"}
```

Ping `creative.play.example`:

```sh
node ping.mjs creative.play.example 25595
```

```json
{"host":"creative.play.example","version":"1.21.4","motd":"Creative backend"}
```

Ping a hostname not listed in `routes.json`. Sculkworm closes the connection with zero bytes written:

```sh
node ping.mjs unknown.play.example 25595
```

```text
Error: Connection closed before the server sent a status response
```

## 5. Hot-reload routes with SIGHUP

Add a third hostname (`lobby.play.example`) by writing a temporary file and replacing `config/routes.json` atomically, then send `SIGHUP` to the container:

```sh
cat > config/routes.json.tmp <<'EOF'
{
  "routes": {
    "survival.play.example": "host.docker.internal:25581",
    "creative.play.example": "host.docker.internal:25582",
    "lobby.play.example": "host.docker.internal:25581"
  }
}
EOF
mv config/routes.json.tmp config/routes.json
docker kill --signal=HUP sculkworm
```

```text
sculkworm
```

Ping the newly added hostname without restarting the container:

```sh
node ping.mjs lobby.play.example 25595
```

```json
{"host":"lobby.play.example","version":"1.21.4","motd":"Survival backend"}
```

## 6. Shut down and inspect the full logs

Stop the container gracefully (`SIGTERM`), inspect every log line emitted during the walkthrough, and clean up:

```sh
docker stop sculkworm
docker logs sculkworm
```

```text
level=info event=listening addr=0.0.0.0:25565 routes=2
level=info event=route host=survival.play.example target=host.docker.internal:25581 intent=status protocol=769 peer=172.17.0.1:59278
level=info event=closed host=survival.play.example target=host.docker.internal:25581 bytes_up=45 bytes_down=145 peer=172.17.0.1:59278
level=info event=route host=creative.play.example target=host.docker.internal:25582 intent=status protocol=769 peer=172.17.0.1:59282
level=info event=closed host=creative.play.example target=host.docker.internal:25582 bytes_up=45 bytes_down=145 peer=172.17.0.1:59282
level=info event=unknown_host host=unknown.play.example peer=172.17.0.1:55140
level=info event=reloaded routes=3
level=info event=route host=lobby.play.example target=host.docker.internal:25581 intent=status protocol=769 peer=172.17.0.1:55154
level=info event=closed host=lobby.play.example target=host.docker.internal:25581 bytes_up=42 bytes_down=145 peer=172.17.0.1:55154
level=info event=shutdown
```

Remove the container and stop the local backends:

```sh
docker rm sculkworm
kill "$BACKENDS_PID"
```

```text
sculkworm
```

## Next steps

- Read [Configuration](https://docs.sculk.network/nightly/sculkworm/configuration.md) for every `SCULKWORM_*` environment variable and route validation error.
- Read [Deploying](https://docs.sculk.network/nightly/sculkworm/deploy.md) for Docker Compose, `SIGHUP` reload error handling, and TCP proxy behavior.
- Read [Security model](https://docs.sculk.network/nightly/sculkworm/security.md) before exposing Sculkworm to the public internet.
