From 7bfe3137bd14e37fa6584754083662d70e0cc1a6 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 5 Oct 2026 03:23:18 +0800 Subject: [PATCH] =?UTF-8?q?docker:=20the=20image=20has=20bash=20and=20busy?= =?UTF-8?q?box,=20so=20a=20terminal=20in=20the=20container=20opens=20(?= =?UTF-8?q?=E3=82=B9=E3=83=A9=E3=82=A4=E3=83=A0=20on=20Discord:=20?= =?UTF-8?q?=E8=BF=992=E5=A4=A9=E7=9A=84docker=E7=89=88=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=90=8E=E6=97=A0=E6=B3=95=E8=BF=9B=E5=85=A5terminal=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E5=AF=BC=E8=87=B4=E9=85=8D=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E4=BA=86devin=20=E2=80=A6=20exec:=20"/bin/bash":=20stat=20/bin?= =?UTF-8?q?/bash:=20no=20such=20file=20or=20directory)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The image is distroless, which has no shell at all, so a NAS panel's terminal (Synology, 1Panel, Portainer open /bin/bash or /bin/sh) and `docker exec -it magpie bash` failed, and a sign-in that needs a terminal (magpie accounts add devin) couldn't be made there. The image now copies in Debian 12's bash with the libtinfo it links (distroless cc is Debian 12, so its glibc runs it) and busybox's commands, and puts magpie on PATH (/usr/local/bin/magpie). The image still runs as nonroot and starts /magpie serve as before; it grows from about 37 MB of extras to 66.6 MB. Built locally (docker 29.4, arm64): bash 5.2.15 and sh run as uid 65532, `magpie version` and `magpie healthcheck` work from bash, the gateway answers 200 on /v1/models, /config keeps its folders. The Docker workflow's smoke test now runs bash and sh in the container. README says so. --- .github/workflows/docker.yml | 4 ++++ Dockerfile | 20 ++++++++++++++++++++ README.md | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6a297faf8..5fdda0daf 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -51,6 +51,10 @@ jobs: done test "$READY" = 1 + # a NAS panel's terminal opens bash or sh, with magpie on PATH + docker exec smoke /bin/bash -c 'magpie healthcheck && ls /config >/dev/null' + docker exec smoke /bin/sh -c 'echo sh works' + CODE=$(curl -s -o /tmp/body.json -w '%{http_code}' \ -H 'Authorization: Bearer magpie' -H 'Content-Type: application/json' \ -d '{"model":"ci-unknown-model","messages":[{"role":"user","content":"hi"}]}' \ diff --git a/Dockerfile b/Dockerfile index d3b7b14f0..1daa2a719 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,12 +12,32 @@ RUN CGO_ENABLED=0 go build -tags nogui -trimpath \ -ldflags "-s -w -X main.version=${VERSION}" -o /out/magpie . \ && mkdir -p /config/home /config/cache /config/data /config/state +# A shell for the container's terminal: NAS panels (Synology, 1Panel, +# Portainer) open /bin/bash or /bin/sh, and distroless has neither, so a +# terminal there failed with "stat /bin/bash: no such file or directory". +# Debian 12's bash (with the libtinfo it links), which runs on the glibc of +# distroless's own Debian 12, and busybox for ls, cat and the like. +FROM debian:12-slim AS shell +RUN mkdir -p /out/bin /out/lib \ + && cp /bin/bash /out/bin/bash \ + && cp -L "$(ldd /bin/bash | awk '/libtinfo/ {print $3}')" /out/lib/ + +FROM busybox:1.37-uclibc AS busybox + # cc, not static: plugins run on Bun, which magpie downloads on first use # and which needs glibc (static has no libc at all, and Bun's musl build # would need musl). cc is static plus glibc, libgcc and libstdc++. FROM gcr.io/distroless/cc-debian12:nonroot COPY --from=build /out/magpie /magpie +COPY --from=busybox /bin/busybox /bin/busybox +COPY --from=shell /out/bin/bash /bin/bash +COPY --from=shell /out/lib/ /usr/lib/ +# busybox's commands, and magpie on PATH, so `magpie accounts add …` works +# in that terminal +USER root +RUN ["/bin/busybox", "sh", "-c", "/bin/busybox --install -s /bin && mkdir -p /usr/local/bin && ln -s /magpie /usr/local/bin/magpie"] +USER nonroot COPY --from=build --chown=65532:65532 /config /config # Everything magpie and the sign-ins it manages write goes into the volume: diff --git a/README.md b/README.md index 30810f9bd..6f5189e04 100644 --- a/README.md +++ b/README.md @@ -788,7 +788,9 @@ Termux uses the Android terminal build: the installer puts it in ### Docker `docker build` makes a server image: the terminal-only binary on -distroless (`cc`, for the glibc the plugins' Bun needs), run as nonroot, +distroless (`cc`, for the glibc the plugins' Bun needs) with bash and +busybox for a terminal in the container (`docker exec -it magpie bash`, or a +NAS panel's terminal; `magpie` is on its PATH), run as nonroot, with everything it keeps in a volume at `/config`: magpie's own files (`/config/magpie`), the sign-ins kept where their agent keeps them (HOME is `/config/home`, so `~/.codex`, `~/.claude`… are in it) and the cache with the