|
| 1 | +# Podman Quadlet Example |
| 2 | + |
| 3 | +This example demonstrates how to deploy multiple autoscaling minecraft servers behind mc-router with [podman quadlets](https://docs.podman.io/en/stable/markdown/podman-systemd.unit.5.html). |
| 4 | + |
| 5 | +The commands listed below assume rootless podman but can easily be modified for rootful. |
| 6 | + |
| 7 | +## mc-router.host label |
| 8 | + |
| 9 | +In `mc@.container`, replace `example.com` with your domain. |
| 10 | + |
| 11 | +## Server instance configuration |
| 12 | + |
| 13 | +Each server instance requries an environment file with a matching name in the mc folder; e.g. instance `example` uses `mc/example.env`.[^1] |
| 14 | + |
| 15 | +## Container auto-removal fix |
| 16 | + |
| 17 | +Once the quadlets files are installed and daemon-reloaded, the generated service file needs to be edited due to generated quadlets always adding `--rm`.[^2] |
| 18 | +To fix this, run `systemctl --user edit mc@.service` and replace the `ExecStart` entry with a copy that substitues `--restart=unless-stopped` where `--rm` is. |
| 19 | +The drop-in should look something like this: |
| 20 | + |
| 21 | +```ini |
| 22 | +[Service] |
| 23 | +ExecStart= |
| 24 | +ExecStart=/usr/bin/podman run --name %p-%i --replace --restart=unless-stopped ... |
| 25 | +``` |
| 26 | + |
| 27 | +## Start containers/services |
| 28 | + |
| 29 | +```sh |
| 30 | +systemctl --user enable --now podman.socket |
| 31 | +systemctl --user start mc@example.service mc-router.service |
| 32 | +# instances are enabled by symlinking from the template |
| 33 | +ln -s ${XDG_CONFIG_HOME}/containers/systemd/mc@.service ${XDG_CONFIG_HOME}/containers/systemd/mc@example.service |
| 34 | +``` |
| 35 | + |
| 36 | +## Rootless notes |
| 37 | + |
| 38 | +If running rootless, be sure to enable lingering with `sudo loginctl enable-linger $USER`. |
| 39 | + |
| 40 | +Also note that source IPs are currently lost due to how rootless podman handles custom networks. |
| 41 | +This should be fixed in a future podman release.[^3] |
| 42 | + |
| 43 | +[^1]: The base config is a [template file](https://docs.podman.io/en/stable/markdown/podman-systemd.unit.5.html#template-files) with instance names after the @ sign . |
| 44 | +[^2]: <https://github.com/podman-container-tools/podman/discussions/28837> |
| 45 | +[^3]: <https://github.com/podman-container-tools/podman/pull/28478> |
0 commit comments