feat(agent): report isDocker so the web shows a docker pull command

The binary self-update hard-stops inside a container (internal/upgrade
refuses when /.dockerenv exists), so the web's in-app 'force update' button
is futile for Docker agents. Report whether we run in a container via a new
RunningInDocker() helper (UNARR_DOCKER env baked into the image, /.dockerenv
fallback for podman/containerd) on every register + sync, so the web can
swap the button for a copy-paste 'docker compose pull' command.
This commit is contained in:
Deivid Soto 2026-06-03 18:09:29 +02:00
parent ccd50e7c8e
commit 2148b0e2cc
5 changed files with 42 additions and 0 deletions

26
internal/agent/docker.go Normal file
View file

@ -0,0 +1,26 @@
package agent
import "os"
// RunningInDocker reports whether the agent process is running inside a Docker
// (or compatible OCI) container. The web uses this to swap the in-app "force
// update" button — which drives the binary self-update path that hard-stops
// inside a container (see internal/upgrade) — for a copy-paste `docker pull`
// command instead.
//
// Detection order:
// 1. UNARR_DOCKER env truthy — baked into the official image's Dockerfile, so
// it also covers podman/containerd running our image (which don't create
// /.dockerenv).
// 2. /.dockerenv exists — the standard marker Docker writes into every
// container, covering images that didn't set the env.
func RunningInDocker() bool {
switch os.Getenv("UNARR_DOCKER") {
case "1", "true", "yes":
return true
}
if _, err := os.Stat("/.dockerenv"); err == nil {
return true
}
return false
}