# Running in Docker Run termlessd as a container with Docker Compose. The files in the release folder, the first start, settings, putting it on your domain with Caddy or a Cloudflare Tunnel, everyday commands, upgrades, backups and moving over from systemd. The release folder can run Termless as a system service ([Running the server](/docs/running)) or as a Docker container. Both run the same binary with the same data, so the choice is about the box: - **Docker** when the box already runs its services in Docker, or you want Termless as one folder you start, stop, move and delete as a unit. - **systemd** for the smallest footprint: no Docker daemon, and the unit already locks the process down as tightly as the container does. You can move from one to the other later by copying the data folder ([below](#moving-from-systemd-to-docker)). ## What you need - Docker Engine with Compose v2: `docker compose version` prints a version. - The release folder for the box's processor, `termless--linux-x86_64` or `termless--linux-aarch64` (`uname -m` tells you which; `arm64` is `aarch64`). | File | What it is | |---|---| | `termlessd` | The server, for this processor. | | `Dockerfile` | Packs it into an image with nothing else inside: no shell, no libc, no package manager. The binary carries its own root certificates. | | `compose.yaml` | The service: a data volume, the port on `127.0.0.1` only, an allowlist, a read-only file system, no capabilities, a 512 MB memory cap, an unprivileged user (uid 10001). Its image is tagged with the release's version (`termless:`), so each release folder runs its own. | | `compose.caddy.yaml` | Adds Caddy, with HTTPS on your domain. | | `compose.cloudflare.yaml` | Adds a Cloudflare Tunnel. | | `Caddyfile` | Caddy's configuration for `compose.caddy.yaml`. | | `example.env` | The settings, to copy to `.env`. | | `upgrade-docker.sh` | Moves a running install to this release: copies your settings, builds the new image while the old one keeps running, backs up the data, restarts on the new image, checks it started. | | `CHANGES.md` | What changed in this release and the ones before it, and when the database changed (the [What's new](/docs/releases) page). | | `SHA256SUMS` | The SHA-256 of every file in the folder: `sha256sum -c SHA256SUMS` checks them. | ## First start In the release folder: ```sh cp example.env .env docker compose up -d --build docker compose logs termless ``` The log shows a one-time **setup token**. Open `http://127.0.0.1:8780` on the box, or from your own computer through an SSH tunnel: ```sh ssh -N -L 8780:127.0.0.1:8780 you@your-box ``` and then `http://127.0.0.1:8780` in your browser. Enter the token and choose the admin password (15 to 200 characters with a lowercase letter, a capital, a digit and a symbol; a long random one is best). Then **Accounts > Add account**, and **API keys** for each app that will use it. The rest of these docs are on the same server at `/docs`. ## Settings `.env`, next to `compose.yaml`, holds what you change: | Setting | Default | What | |---|---|---| | `COMPOSE_FILE` | `compose.yaml` | Which compose files to use, separated by `:`. Add `compose.caddy.yaml` or `compose.cloudflare.yaml` for a domain (below). | | `TERMLESS_PORT` | `8780` | The port on the box. It is always bound to `127.0.0.1`. | | `TERMLESS_TRUST_PROXY` | `0` | `1` when a proxy installed on the box itself (outside Docker) forwards to that port. | | `TERMLESS_DOMAIN` | | Your domain, for `compose.caddy.yaml`. | | `TUNNEL_TOKEN` | | The tunnel's token, for `compose.cloudflare.yaml`. | Any other termlessd setting from [Running the server](/docs/running#settings) goes in a file of your own, `compose.local.yaml`, so an upgrade never overwrites it; add it to `COMPOSE_FILE` in `.env` (for example `COMPOSE_FILE=compose.yaml:compose.local.yaml`): ```yaml services: termless: environment: TERMLESS_LOG: info,termless=debug ``` After a change: `docker compose up -d`. Do not edit `compose.yaml` itself; the next release replaces it. ## On your own domain ### With Caddy Caddy runs as a second container and gets the certificate by itself. 1. Point the domain at the box: an `A` record (and `AAAA` for IPv6) for the name, **DNS only** if the domain is on Cloudflare. [Your own domain](/docs/domains#caddy) explains both steps. 2. Open ports 80 and 443 in the box's firewall and in the cloud provider's firewall. 3. In `.env`: ```sh COMPOSE_FILE=compose.yaml:compose.caddy.yaml TERMLESS_DOMAIN=termless.example.com ``` 4. `docker compose up -d`. The certificate arrives with the first visit to `https://termless.example.com`. If another web server already holds ports 80 and 443 on the box, keep it: give it a site that proxies to `127.0.0.1:8780` ([Your own domain](/docs/domains) has the Caddy and nginx versions), keep `COMPOSE_FILE=compose.yaml`, and set `TERMLESS_TRUST_PROXY=1` in `.env`. ### With a Cloudflare Tunnel No port is opened and the box's address stays private. The domain must be on Cloudflare. 1. In the Cloudflare dashboard: **Zero Trust > Networks > Tunnels > Create a tunnel**, type **Cloudflared**. Skip installing a connector there; copy the **token** from the install command it shows (the long string after `--token` or `install`). 2. Add a public hostname: your subdomain and domain, service type `HTTP`, URL `termless:8780`. 3. In `.env`: ```sh COMPOSE_FILE=compose.yaml:compose.cloudflare.yaml TUNNEL_TOKEN=paste-the-token-here ``` 4. `docker compose up -d`. The tunnel shows as healthy in Cloudflare within seconds. The compose file also sets what termlessd needs behind Cloudflare: the visitor's address from `CF-Connecting-IP` and an always-`Secure` cookie. To ask for a sign-in before the page loads, see [a sign-in in front](/docs/domains#a-sign-in-in-front-optional). Check either way with the steps in [Check it worked](/docs/domains#check-it-worked). ## Everyday commands Run them in the release folder. | To | Run | |---|---| | Follow the log | `docker compose logs -f termless` | | Check the box | `docker compose exec termless /termlessd doctor` | | See what is running | `docker compose ps` | | Stop, start | `docker compose stop`, `docker compose start` | | Remove the containers, keep the data | `docker compose down` | | Remove everything, data too | `docker compose down -v` (accounts, keys and trails are gone for good) | The image has no shell, so `docker compose exec termless sh` does not work; run `/termlessd` with a command (`doctor`, `passwd`, `version`) instead. To change the admin password, use **Change password** in the dashboard (the account menu at the bottom of the sidebar). If you cannot sign in any more, set a new one from the box; `read -rs` keeps it off the screen and out of the shell history: ```sh read -rs PW && printf '%s\n' "$PW" | docker compose exec -T termless /termlessd passwd; unset PW docker compose restart termless ``` ## Upgrading The data volume belongs to the compose project (named `termless` in `compose.yaml`), not to a folder, so a new release folder runs on the same accounts, keys and history. Unpack the new release next to the old one and run its upgrade script, naming the old folder: ```sh tar xzf termless--linux-x86_64.tar.gz cd termless--linux-x86_64 sh upgrade-docker.sh ../termless--linux-x86_64 ``` Step by step, it: 1. copies `.env` (and `compose.local.yaml`) from the old folder; 2. builds this release's image (`termless:`) while the old container keeps running, and reads the new version from that image, so nothing runs on the box itself; 3. stops the container and saves the data volume to `backups/termless-data-