BZFlag Server Container
=======================

We provide a Dockerfile for those who wish to run BZFlag servers inside containers. Adding custom plugins or source code
changes is easy as it copies the local source code into the build container. The example commands below will use the
docker command, but should also work with the podman command.

Building the container
----------------------

Building a stock BZFlag server container:
  docker build . -t bzflag-server:latest

Custom plugins placed in the plugins/ directory can be built by passing a comma separated list of directory names as a
build argument:
  docker build . -t bzflag-server:latest --build-arg plugins="UselessMine,mapchange"

It is also possible to supply custom arguments to the configure script:
  docker build . -t bzflag-server:latest --build-arg configure="--enable-custom-plugins-file=plugins.txt"

Troubleshooting
---------------

> [stage-1 2/5] RUN apk update && apk upgrade --no-cache &&     apk add --no-cache c-ares libcurl libgcc libstdc++ zlib\
    &&     adduser -S bzfsd &&     mkdir /data && chown bzfsd:nogroup /data:
> 0.393 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
> 5.394 WARNING: updating and opening https://dl-cdn.alpinelinux.org/alpine/v3.20/main: temporary error (try again later)

If the build process fails due to network errors on the `apk update` step, then it may be a DNS problem with your Docker
engine configuration. Add the `--network=host` flag to your `docker build` command to use your host machine's DNS
instead of Docker's internal DNS.

Running a self-built image
--------------------------

Assume that the configuration, world, groupdb, etc for a given server are stored in a subdirectory of /srv/bzfs/, such
as /srv/bzfs/5154. The configuration file is at /srv/bzfs/5154/config.

Start a server that automatically starts when the system boots up (and restarts if bzfs exits or crashes):
  docker run -d --restart unless-stopped -p 0.0.0.0:5154:5154/tcp -p 0.0.0.0:5154:5154/udp -v /srv/bzfs/5154:/data \
    --name bzfs5154 bzflag-server:latest -conf config

Note that podman does not automatically start containers when the host system reboots. You must externally manage them
with some other method, such as a systemd unit. Podman supports the generation of unit files. Build and run the
container first. Then you need to use loginctl to enable linger so that the user unit can start without requiring you to
first log in to the user. Then you use podman to generate a systemd unit and enable it.
  sudo loginctl enable-linger UsernameHere
  mkdir -p ~/.config/systemd/user/
  podman generate systemd --new --name bzfs5154 > ~/.config/systemd/user/bzfs5154.service
  podman stop bzfs5154 && podman rm bzfs5154
  systemctl --user daemon-reload
  systemctl --user enable bzfs5154.service --now

List running and stopped containers:
  docker ps -a

Stop a running server:
  docker stop bzfs5154

Start a stopped server:
  docker start bzfs5154

Remove a stopped server:
  docker rm bzfs5154

