From c1d5241fb2205731c43b96ca2384091591d588e5 Mon Sep 17 00:00:00 2001 From: Lenart Kos <39205323+Lenart12@users.noreply.github.com> Date: Tue, 20 Jan 2026 19:59:04 +0100 Subject: [PATCH] Add autoscaling documentation and examples for mc-router integration (#3826) --- docs/misc/autoscale/autoscale.md | 39 +++++++++++++++ docs/misc/examples.md | 42 ++++++++++++++++ .../mc-router-autoscale/compose-minimal.yml | 27 ++++++++++ examples/mc-router-autoscale/compose.yml | 50 +++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 docs/misc/autoscale/autoscale.md create mode 100644 examples/mc-router-autoscale/compose-minimal.yml create mode 100644 examples/mc-router-autoscale/compose.yml diff --git a/docs/misc/autoscale/autoscale.md b/docs/misc/autoscale/autoscale.md new file mode 100644 index 00000000..597bfd42 --- /dev/null +++ b/docs/misc/autoscale/autoscale.md @@ -0,0 +1,39 @@ + +# Autoscaling (sleep when idle) + +Autoscaling (sometimes called *sleeping*, *scale to zero* or *wake on join*) is the pattern of stopping a Minecraft server when nobody is playing and starting it again when someone tries to connect with the intention of saving resources when the server is not in use (e.g., on a VPS with limited CPU/RAM or a home server). + +## mc-router + +[mc-router](https://github.com/itzg/mc-router) is a Minecraft-aware router/multiplexer. + +- Routes players by the hostname they connect with (useful for multiple servers behind one port) +- Can auto-start a backend container on join and stop it again after an idle timeout + +Examples: + +- See the mc-router section in [Examples](../examples.md#mc-router-with-auto-scale) + +## Lazymc + +[Lazymc](https://github.com/timvisee/lazymc) can keep a server “asleep” until a player connects. With Docker it’s commonly used via [lazymc-docker-proxy](https://github.com/joesturge/lazymc-docker-proxy). + +- Players connect to the proxy; the proxy starts/stops the server container +- Usually requires a static IP for the Minecraft container on a user-defined network + +Example: + +- See the Lazymc section in [Examples](../examples.md#lazymc-put-your-minecraft-server-to-rest-when-idle) + +## Lazytainer + +[Lazytainer](https://github.com/vmorganp/Lazytainer) starts/stops containers based on network traffic. + +- Uses packet thresholds + inactivity timeouts (not Minecraft hostname aware) +- Can be triggered by port scans/pings in noisy environments + +Example: + +- See the Lazytainer section in [Examples](../examples.md#lazytainer-stop-minecraft-container-based-on-traffic) + + diff --git a/docs/misc/examples.md b/docs/misc/examples.md index 4b792328..eb91ba61 100644 --- a/docs/misc/examples.md +++ b/docs/misc/examples.md @@ -27,6 +27,48 @@ services: [Source](https://github.com/itzg/docker-minecraft-server/blob/master/examples/geyser/docker-compose.yml) + +## mc-router with auto-scale + +Using [mc-router](https://github.com/itzg/mc-router) in front of one or multiple Minecraft server containers allows you to route players based on the hostname they use to connect. + +With `AUTO_SCALE_UP` and `AUTO_SCALE_DOWN` enabled, mc-router can automatically start a target server when a player connects and stop it again after a period of inactivity. + +```yaml title="compose.yaml" +services: + router: + image: itzg/mc-router + environment: + IN_DOCKER: true + AUTO_SCALE_DOWN: true + AUTO_SCALE_UP: true + AUTO_SCALE_DOWN_AFTER: 2h + AUTO_SCALE_ASLEEP_MOTD: "Server is asleep. Join again to wake it up!" + ports: + - "25565:25565" + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + + vanilla: + image: itzg/minecraft-server + environment: + EULA: "TRUE" + labels: + mc-router.host: "vanilla.example.com" + + paper: + image: itzg/minecraft-server + environment: + EULA: "TRUE" + TYPE: PAPER + labels: + mc-router.host: "paper.example.com" +``` + +[Source](https://github.com/itzg/mc-router/blob/main/examples/docker-autoscale/compose-minimal.yml) + +[More detailed example](https://github.com/itzg/mc-router/blob/main/examples/docker-autoscale/compose.yml) + ## Lazymc - Put your Minecraft server to rest when idle With [lazymc-docker-proxy](https://github.com/joesturge/lazymc-docker-proxy) you are able to use [lazymc](https://github.com/timvisee/lazymc) with the minecraft container. diff --git a/examples/mc-router-autoscale/compose-minimal.yml b/examples/mc-router-autoscale/compose-minimal.yml new file mode 100644 index 00000000..f117976f --- /dev/null +++ b/examples/mc-router-autoscale/compose-minimal.yml @@ -0,0 +1,27 @@ +# Source: https://github.com/itzg/mc-router/blob/main/examples/docker-autoscale/compose-minimal.yml +services: + router: + image: itzg/mc-router + environment: + IN_DOCKER: true + AUTO_SCALE_DOWN: true + AUTO_SCALE_UP: true + AUTO_SCALE_DOWN_AFTER: 2h + AUTO_SCALE_ASLEEP_MOTD: "Server is asleep. Join again to wake it up!" + ports: + - "25565:25565" + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + vanilla: + image: itzg/minecraft-server + environment: + EULA: "TRUE" + labels: + mc-router.host: "vanilla.example.com" + paper: + image: itzg/minecraft-server + environment: + EULA: "TRUE" + TYPE: PAPER + labels: + mc-router.host: "paper.example.com" diff --git a/examples/mc-router-autoscale/compose.yml b/examples/mc-router-autoscale/compose.yml new file mode 100644 index 00000000..11900c1d --- /dev/null +++ b/examples/mc-router-autoscale/compose.yml @@ -0,0 +1,50 @@ +# Source: https://github.com/itzg/mc-router/blob/main/examples/docker-autoscale/compose.yml +# This is a verbose example with comments and explanations for configuring auto-scaling behavior +# for Docker backend servers. See compose-minimal.yml for a simple minimal example. +services: + router: + image: itzg/mc-router + environment: + IN_DOCKER: true + # Global auto-scaling settings for all docker-backend servers + # Settings can be overridden per-backend using labels + # as shown in the backend services below (except for AUTO_SCALE_DOWN_AFTER which is global only) + # Enable auto-scaling down after inactivity for all backends by default + AUTO_SCALE_DOWN: true + # Enable auto-scaling up after player join for all backends by default + AUTO_SCALE_UP: true + # Time of inactivity after which to scale down (default: 10m) - Global only setting + AUTO_SCALE_DOWN_AFTER: 2h + # MOTD to show when server is asleep (default: empty string - don't show MOTD, show server offline instead) + AUTO_SCALE_ASLEEP_MOTD: "Server is asleep. Join again to wake it up!" + ports: + - "25565:25565" + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + vanilla: + image: itzg/minecraft-server + environment: + EULA: "TRUE" + labels: + # If global auto scaling settings are enabled, this backend will + # auto-scale without any additional auto-scale related configuration + mc-router.host: "vanilla.example.com" + fabric: + image: itzg/minecraft-server + environment: + EULA: "TRUE" + TYPE: FABRIC + labels: + mc-router.host: "fabric.example.com" + # Disable auto-scaling for this backend specifically + mc-router.auto-scale-up: false + mc-router.auto-scale-down: false + paper: + image: itzg/minecraft-server + environment: + EULA: "TRUE" + TYPE: PAPER + labels: + mc-router.host: "paper.example.com" + # Override asleep MOTD for this backend + mc-router.auto-scale-asleep-motd: "Paper is folded. Join to unfold!"