Add autoscaling documentation and examples for mc-router integration (#3826)

This commit is contained in:
Lenart Kos
2026-01-20 19:59:04 +01:00
committed by GitHub
parent 1565d08949
commit c1d5241fb2
4 changed files with 158 additions and 0 deletions

View File

@@ -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 its 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)

View File

@@ -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.

View File

@@ -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"

View File

@@ -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!"