Docker Compose configuration for Beszel monitoring service
  • Dockerfile 69.6%
  • Shell 30.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-06 19:37:04 +00:00
scripts script to check local docker GID 2026-12-06 14:23:25 +00:00
.env.example merged compose 2026-12-06 19:37:04 +00:00
.gitattributes Initial commit: add gitattributes, gitignore, zipignore, docker-compose, README, and env template 2026-12-06 12:16:47 +00:00
.gitignore multi-hubs 2026-12-06 18:55:26 +00:00
.zipignore env variable adjust 2026-12-06 19:32:10 +00:00
docker-compose.yml merged compose 2026-12-06 19:37:04 +00:00
ENV.md merged compose 2026-12-06 19:37:04 +00:00
README.md merged compose 2026-12-06 19:37:04 +00:00

Beszel

Local Beszel Hub and Agent running under Docker Compose. The Hub stores its PocketBase database and keys in ./data, the Agent stores its state in ./agent, and the two share ./socket. The agent monitors the standard host Docker daemon by default. No separate database, reverse proxy or healthcheck container is needed. An optional beszel-proxy service publishes the Agent’s Unix socket over TCP for multi-Hub monitoring on a trusted private network; see Monitor multiple servers from multiple Hubs.

Before You Start

  • Use the same Docker context/daemon as the existing deployment. The default socket is /var/run/docker.sock; change DOCKER_SOCKET_PATH for another daemon.
  • Run ./scripts/get-docker-gid.sh from the project directory to detect the socket group ID and optionally update .env (do not assume the template's 999 is correct).
  • All services run as UID/GID 1000 by default. The selected user needs writable persistent directories and the agent needs access to the Docker socket. Access to Docker's API is effectively privileged even with a read-only bind mount; the mount does not restrict API methods. Use a restricted socket proxy if you need a stronger boundary.
  • Use a recent Docker Compose release with support for service scaling, environment-backed secrets and healthcheck start intervals. Ensure the Docker Engine also supports healthcheck start intervals.

Update an existing installation

  1. Stop the old stack with docker compose down --remove-orphans from the project directory before replacing its Compose file. Back up .env, data/ and agent/ securely while stopped. Do not delete the Hub database or keys.

  2. Extract this archive into the existing project directory. No .env or runtime data is shipped, so existing credentials and database files are not overwritten.

  3. Merge the settings in .env.example into the existing .env using vim .env. If upgrading from the profile-based proxy release, replace the previous COMPOSE_PROFILES=remote setting with EXTERNAL_CONNECTIONS_ENABLED=1 if remote monitoring is desired; rename PROXY_BIND_IP and PROXY_PORT to EXTERNAL_CONNECTIONS_BIND_IP and EXTERNAL_CONNECTIONS_PORT while keeping their values. If upgrading from the two-file boolean release, change EXTERNAL_CONNECTIONS_ENABLED from true to 1 or false to 0 and remove the obsolete docker-compose.external-connections.yml file. Remove the obsolete profile setting and unset any shell overrides. Preserve your existing APP_URL, KEY and TOKEN values and any intentional custom settings. Optional commented entries can remain commented. Run ./scripts/get-docker-gid.sh to detect and save the socket path and GID; use chmod 600 .env.

  4. Prepare the directories and change ownership to the configured UID/GID while the containers are stopped:

    sudo mkdir -p data agent socket
    sudo chown -R 1000:1000 data agent socket
    

    Replace 1000:1000 if using different IDs. This is needed when the previous containers created root-owned data. Never change ownership or permissions of the host Docker socket itself.

  5. Run docker compose config --quiet and docker compose up -d --remove-orphans.

  6. Verify docker compose ps and docker compose logs --tail=100. Check the system is online and container metrics are populated. Existing Hub keys and registration tokens should remain valid; no re-enrollment is expected.

Fresh installation

1. Prepare the configuration

cp .env.example .env
chmod 600 .env
vim .env

Set these values in .env before starting the Hub:

  • APP_URL: the browser-facing URL, e.g. http://localhost:8090 or your actual domain.
  • DOCKER_SOCKET_PATH: /var/run/docker.sock for a standard Docker installation.
  • DOCKER_SOCKET_GID: the numeric group ID detected by ./scripts/get-docker-gid.sh.
  • HUB_URL: http://127.0.0.1:8090 in .env.example for the normal local WebSocket connection. If you change BESZEL_HOST_PORT, update this URL to match the published port. Keep this setting in .env for standalone mode; remove it entirely for SSH-only multi-Hub mode.
  • LISTEN: /beszel_socket/beszel.sock for the local agent.
  • KEY and TOKEN: leave empty until the Hub generates them in step 3.

Run the socket helper from the project directory and confirm the values before saving:

./scripts/get-docker-gid.sh

Create the persistent directories before Docker can create them as root:

sudo mkdir -p data agent socket
sudo chown -R 1000:1000 data agent socket

Use your configured USER_UID:USER_GID instead of 1000:1000 if different.

2. Start the Hub and create an account

Start only the Hub (the agent does not have credentials yet):

docker compose up -d beszel
docker compose ps

Open http://localhost:8090 in your browser, or use the configured APP_URL if accessing from another machine or domain. Create the initial administrator account and sign in.

3. Add the local system and obtain the credentials

  1. In the Beszel dashboard, click Add System.
  2. Enter a descriptive Name, such as your server's hostname.
  3. In Host / IP, enter /beszel_socket/beszel.sock. This must match LISTEN in .env. Leave the port at its default if shown; TCP port configuration is not needed for the Unix socket.
  4. Copy the Public Key (the entire ssh-ed25519 ... value) and the Token from this dialog. If copying the generated Docker Compose snippet instead, extract only its KEY and TOKEN values; this project already provides its own Compose file.
  5. Click Add System to save the system. Use the token from the same dialog used to save the system, rather than opening another dialog to generate a different token.

The Hub generates the key pair and registration token; do not generate a separate SSH key pair. The system may initially show Down until the agent starts.

The Beszel communication socket (/beszel_socket/beszel.sock) is not the Docker monitoring socket (/var/run/docker.sock). Do not enter the Docker socket path in Host / IP.

4. Configure the agent credentials

Edit .env again:

vim .env

Set the two existing entries to the values copied from the Hub, for example:

KEY="ssh-ed25519 AAAAC3..."
TOKEN="your-generated-system-token"

Replace both example values with the complete, actual values. KEY is the Hub's public key, not a private key. TOKEN is the system registration credential; keep it confidential. This project passes it to the agent via the Compose secret and TOKEN_FILE=/run/secrets/beszel_token. Leave TOKEN_FILE at its default; no separate token file needs to be created manually. Do not commit .env.

5. Start the agent and verify registration

docker compose config --quiet
docker compose up -d
docker compose ps
docker compose logs --tail=100 beszel-agent

Return to the dashboard and verify the system becomes Up and host/container metrics appear. If it remains Down, check the agent logs, confirm KEY and TOKEN were copied from the saved system's dialog, and verify that LISTEN and the Hub's Host / IP match. See the troubleshooting section below for permissions and socket checks.

For future restarts or updates, retain .env, data/ and agent/; you do not normally need to add the system again or regenerate credentials.

Upstream reference: Beszel Hub installation.

Monitor multiple servers from multiple Hubs

Each server keeps its own Hub, Agent, database, dashboard and alerts. In remote mode the Agent uses SSH polling over its original Unix socket. The local Hub connects directly to that socket; the optional beszel-proxy container runs socat on bridge networking and forwards remote TCP connections to the same socket. SSH authentication remains end-to-end between each Hub and the Agent. The proxy has no Docker socket, database, private keys or registration tokens.

  • X (central): Hub monitors X locally and Y/Z through their proxy ports. No proxy is required on X unless other Hubs need to monitor it.
  • Y and Z: their own Hubs monitor locally over /beszel_socket/beszel.sock; their proxies accept X over the private network.
  • Full mesh: enable the proxy on every monitored host and authorize the public keys of all intended Hubs. Add the remote records to each Hub independently. History and alerts are not replicated.

The Agent retains host networking to measure host network interfaces. The Hub and proxy use the normal Compose bridge. Local monitoring does not require the private network, a Docker bridge firewall rule, Tailscale Serve or a host-installed socat. The remote Hub initiates connections; monitored servers do not need permission to initiate connections to the central Hub.

Before You Start

  • Preserve existing .env, data/, agent/ and socket/. Back up credentials and data before updating. Do not recreate system records or regenerate Hub keys.
  • Keep the local Hub public key, existing local TOKEN, and Docker socket/GID settings. Run the Docker GID helper if container metrics are missing.
  • Identify an existing reachable private IPv4 address on each monitored server, such as its Tailscale address (tailscale ip -4), in the Docker daemon's network namespace. That address must exist when Docker starts the proxy. The central Hub container must be able to reach the address and TCP port.
  • Use a trusted LAN or VPN. The Hub does not verify the Agent SSH host key; never publish the proxy on a public or wildcard address. Docker-published ports can bypass UFW and may be reachable via other interfaces if routing permits; keep Tailscale grants/ACLs and Docker's network restrictions appropriate. No firewall or Tailscale configuration is changed by this project.
  • If upgrading from the previous direct-TCP Agent setup, the old Agent must release port 45876 before the proxy can publish it. Follow the stop/start sequence below.

1. Obtain the central Hub key

On Hub X, open Add System and copy its complete public SSH key (not the private key or token). The same public key authorizes X on Y and Z. If X already monitors those servers, keep its existing records.

2. Configure remote monitoring on Y

In Y's project directory, use vim .env. Preserve the existing keys and token; the example below shows the expected settings. Replace the IP and public-key placeholders with actual values.

BESZEL_AGENT_DISABLE_SSH=false
BESZEL_HUB_DISABLE_SSH=false
EXTERNAL_CONNECTIONS_ENABLED=1
# HUB_URL=http://127.0.0.1:8090
KEY="ssh-ed25519 AAAA_LOCAL_Y_KEY\nssh-ed25519 AAAA_CENTRAL_X_KEY"
LISTEN=/beszel_socket/beszel.sock
NETWORK=unix
EXTERNAL_CONNECTIONS_BIND_IP=100.64.0.2
EXTERNAL_CONNECTIONS_PORT=45876

Keep KEY_FILE unset if using KEY. Multiple public keys are separated by a literal \n inside the double-quoted .env value, which Compose decodes into a newline. If both keys were already configured for direct TCP, leave KEY unchanged. Preserve TOKEN and TOKEN_FILE for local-only rollback; tokens are not used for SSH polling.

Important: remove or comment out every active HUB_URL assignment (do not set it to an empty string) and unset any shell override. A successful WebSocket connection stops the SSH listener, including the Unix socket, which would break the proxy. Keep both SSH-disable flags false. Merely setting EXTERNAL_CONNECTIONS_ENABLED=1 does not change HUB_URL or LISTEN automatically.

EXTERNAL_CONNECTIONS_ENABLED=1 enables one proxy on normal docker compose up commands; 0 (default) sets its replica count to zero, so no proxy container or published agent port remains after a full docker compose up -d. The single Compose file uses this numeric setting directly as the proxy service scale. Use only 0 or 1. No Compose profile or wrapper script is needed. Compose may still pull the proxy image even when its replica count is zero. EXTERNAL_CONNECTIONS_BIND_IP defaults to loopback (127.0.0.1), deliberately not a remote-accessible address. The proxy's internal TCP port is fixed at 45876; EXTERNAL_CONNECTIONS_PORT changes only its published host port. It runs with the same UID/GID as the Agent and mounts only ./socket read-only.

3. Apply the configuration

Stop the old Agent (and any existing proxy) before starting the updated services, so the old direct TCP listener cannot conflict with the new published port. Keep the Hub and its database intact.

unset HUB_URL
docker compose config --quiet
docker compose stop beszel-proxy beszel-agent
docker compose up -d --force-recreate beszel-agent beszel-proxy
docker compose ps
docker compose logs --tail=100 beszel-agent beszel-proxy

The Agent should report an SSH listener on /beszel_socket/beszel.sock. The proxy should publish the configured private address and port. The proxy waits for the Agent to start, not for its connection-dependent healthcheck, to avoid a circular startup dependency. Its own healthcheck verifies that the socket exists and its TCP listener is open; this is not an SSH authentication test.

On Hub Y, edit the existing local system (if previously changed to the Tailscale IP): set Host / IP back to /beszel_socket/beszel.sock. Keep the default port if shown. Save to retain the system history. The local Hub uses the Unix socket directly, regardless of the proxy or Tailscale state.

4. Add or verify Y on Hub X

On Hub X, open Add System (or edit Y's existing record), enter Y's private IP in Host / IP and the configured EXTERNAL_CONNECTIONS_PORT in Port, then save. X uses its own private key, matching the public key authorized on Y. No additional token is needed for SSH polling. If Y was already monitored using the same private address and port, there is no change on X.

Verify Y is Up in both dashboards and Docker metrics appear. Repeat steps 2–4 on Z with its own private address, local key and token, plus X's public key. X's local configuration can stay unchanged.

Remote troubleshooting

docker compose ps
docker compose logs --tail=100 beszel-agent beszel-proxy
docker compose port beszel-proxy 45876
docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' beszel-agent | grep '^HUB_URL='

The last command should produce no output in remote mode. If the agent logs show WebSocket connections, remove the remaining HUB_URL from .env, the shell or a Compose override and recreate the agent. If the proxy logs show permission denied or socket missing, check LISTEN, the shared socket mount and directory ownership. If Docker cannot bind the port, check for the old TCP listener, another process or a missing private IP. Check TCP reachability from the central Hub's network namespace if remote monitoring fails; a host-level check alone does not verify that namespace. No custom UFW INPUT rule is needed for the local Unix connection. Existing network policy still applies to remote traffic.

Disable remote monitoring

Set EXTERNAL_CONNECTIONS_ENABLED=0 in .env and run a full Compose reconciliation (do not target only the Hub or Agent):

docker compose up -d
docker compose ps

The proxy is scaled to zero, removing its container and port mapping. Verify beszel-proxy is absent from the running services. Remove the extra Hub public keys if they are no longer needed. You may leave local SSH polling enabled or restore the original local HUB_URL and token for WebSocket mode. Keep LISTEN=/beszel_socket/beszel.sock and the local system's Unix-socket address. Recreate the Agent if changing its settings. Remote records can be retained for history. No database reset is necessary.

References: Beszel multiple public keys, Beszel security, Compose service scale, Docker port publishing, Docker and UFW, Socat image.

Detect the Docker socket GID

Run ./scripts/get-docker-gid.sh from the directory containing your .env. It reads the existing literal DOCKER_SOCKET_PATH, or defaults to /var/run/docker.sock if none is set. Press Enter to keep the displayed path or enter a different absolute path. The script verifies that it is a Unix socket (symlinks are supported) and prints the numeric group ID of the actual socket.

Confirm the save prompt to update only DOCKER_SOCKET_PATH and DOCKER_SOCKET_GID in .env; other settings and credentials are retained. If .env does not exist, the script offers to create it from .env.example (or with just the two settings if no template exists). Decline to display the settings without saving. The script does not source .env, need sudo for ordinary accessible sockets, modify socket permissions, or start containers. It supports literal socket paths, not dotenv variable expansion.

If the agent is already running, apply the saved settings with:

docker compose up -d --force-recreate beszel-agent

The agent's internal DOCKER_HOST should remain unix:///var/run/docker.sock, even when the host socket path differs.

Health and troubleshooting

The Hub runs its built-in health command against its internal port 8090. The agent starts only when the Hub reports healthy, and has its own health command. The obsolete beszel-health container is removed.

docker compose ps -a
docker compose logs --tail=100 beszel beszel-agent
docker compose exec beszel /beszel health --url http://127.0.0.1:8090
docker compose exec beszel-agent /agent health
docker stats --no-stream beszel beszel-agent

Test the Hub and Docker socket (adjust the published port and socket path if needed):

curl -fsS http://127.0.0.1:8090/api/health
curl --unix-socket /var/run/docker.sock http://localhost/_ping
stat -Lc '%a %u %g' /var/run/docker.sock

The API health endpoint is /api/health, not /health. If the agent cannot read the Docker socket, check DOCKER_SOCKET_GID and recreate the agent. If it cannot open its state or communication socket, check the directory ownership and agent logs. If a stale socket/beszel.sock prevents binding, remove only that socket after stopping both services. If a custom Docker daemon runs in a separate network namespace, run the Hub connectivity test in that namespace; network metrics reflect the namespace exposed to the agent. Non-root operation may also limit optional hardware metrics; do not grant root without a separate security review.

Configuration and maintenance

Update images with docker compose pull && docker compose up -d. Both image tags are configurable. Existing CPU and memory limits are preserved; swap ceilings, log rotation, temporary-directory mounts and non-root users are new. Native Go services and socat do not need init: true merely to satisfy the interpreted-language rule.

Validation

Static checks performed on the delivered files: YAML parse, alphabetical service and environment keys, complete template references, documented defaults, dependency and native healthcheck configuration, secret isolation, and archive exclusion of runtime data. The TCP-to-Unix forwarding command was also exercised with concurrent local socket clients. Live Docker startup, health, credential-file loading, non-root data access, Tailscale port publication and simultaneous Beszel Hub connections must still be verified on the target Docker daemon. Docker is not available in the build environment.