# Running in Docker The image built from the root `Dockerfile` is a microservice for running behind your own reverse proxy. It contains no proxy and no TLS: it serves plain HTTP on port 8080, and the proxy terminates HTTPS. ```sh docker build -t uberbringer . docker run -d -p 127.0.0.1:8080:8080 --stop-timeout 40 \ -v "$PWD/config.toml:/etc/uberbringer/config.toml:ro" \ -v uberbringer-state:/var/lib/uberbringer uberbringer ``` The examples publish the port on the host's loopback address only, for a proxy on the host; a proxy in another container reaches it over a shared Docker network instead, with no `-p` at all. Publish port 8080 only to the proxy, never directly to the internet. ## The config In the mounted `config.toml` ([configuration.md](configuration.md)): - Set `bind_ip = "0.0.0.0"` in `[webserver]`. - Set `trusted_proxies` to the address the proxy's requests come from: its container network (e.g. `["172.18.0.0/16"]`), or for a proxy on the host, the Docker bridge's gateway (usually `172.17.0.1`). Have the proxy set `X-Real-IP` to the client's address. Otherwise every request appears to come from the proxy, and all clients share one rate limit. - Let the proxy pass request bodies up to `webserver.body_limit` (4 MiB by default). The settings can come from [environment variables](configuration.md#environment-variables) instead. To run without a config file, set `UBERBRINGER_CONFIG` empty and put the variables in an env file that only you can read (`chmod 600 uberbringer.env`), so the secret stays off the command line: ```text UBERBRINGER_CONFIG= UBERBRINGER_WEBSERVER_BIND_IP=0.0.0.0 UBERBRINGER_WEBSERVER_TRUSTED_PROXIES=172.18.0.0/16 UBERBRINGER_API_SECRET= UBERBRINGER_PRINTER_ADDRESS=192.168.1.245 ``` ```sh docker run -d -p 127.0.0.1:8080:8080 --stop-timeout 40 --env-file uberbringer.env \ -v uberbringer-state:/var/lib/uberbringer uberbringer ``` ## Health checks For container health checks, use `GET /` to see whether the daemon is up. `/healthz` answers `503` while the printer is unreachable, so it suits alerting better than restarting the container. ## The state directory The image sets [`state.dir`](configuration.md#state) to `/var/lib/uberbringer`, where the daemon keeps its job store, `jobs.db`, so that waiting jobs print after a restart, and where the [ntfy subscriptions](ntfy.md) keep their state. The daemon does not start if it cannot write there. - Mount a named volume there, as the examples do. A new container, after a pull or an upgrade, then takes over the jobs and the subscriptions' state. Without a volume they live in the container and are lost with it, and a container started with `--read-only` does not start at all. The image declares no `VOLUME`, so a container never starts on a fresh, empty one unnoticed. - A bind mount works too, if the directory is owned by the image's user: `sudo chown 10001:10001 state && sudo chmod 700 state`. It must be on a local file system: the store's write-ahead log does not work over a network file system, and a Docker Desktop bind mount passes through a file share of its VM. Use a named volume there. - Stop the container with a timeout above `printer.write_timeout` plus 10 seconds, `--stop-timeout 40` at the defaults, so a receipt being written to the printer can finish. Docker's default, 10 seconds, can kill that write, and the job then reads `uncertain`. - Two containers must never share the directory: the second does not start. ### A job store that will not open If `jobs.db` is damaged, or was written by a newer version, the container stops at start with an error naming the file (`docker logs`). It does not start with an empty store, which would forget the jobs still waiting and which receipts may have printed. To set the store aside, with the container stopped, move `jobs.db` and `jobs.db-wal` out of the volume together, then start it again: ```sh docker stop docker run --rm -v uberbringer-state:/state -v "$PWD:/out" alpine \ sh -c 'mkdir -p /out/broken-store && mv /state/jobs.db* /out/broken-store/' docker start ``` The jobs in the old store are forgotten, so check the last receipts on paper against what was sent. The moved files hold what those receipts printed: delete them once you no longer need them. ## ntfy subscriptions Subscriptions are set in `config.toml` only, so a container with one needs the file. The image runs as user and group `10001`, so give a token file to that ID, mode `600`, and mount it read-only next to the config: ```sh sudo chown 10001:10001 ntfy.token && sudo chmod 600 ntfy.token docker run ... -v "$PWD/ntfy.token:/etc/uberbringer/ntfy.token:ro" uberbringer ```