From 661e836f062acf89704066990fe1e28a94c20962 Mon Sep 17 00:00:00 2001 From: yiling Date: Tue, 23 Jun 2026 09:56:31 +0800 Subject: [PATCH] fix(docker): support non-root/restricted container environments in entrypoint Checks if the container is running as root (UID 0) before executing chown and gosu. If running directly as a non-root user (e.g. in hardened environments like Kubernetes runAsNonRoot or via docker run --user), it directly execs the command, preventing EACCES and permission errors. --- scripts/docker-entrypoint.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 10ae2ac6..0d61b1b9 100644 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -1,13 +1,17 @@ #!/bin/sh set -e -# Check if /app/data exists and is not owned by the bun user (UID 1000) -if [ -d "/app/data" ]; then - if [ "$(stat -c '%u' /app/data)" != "1000" ]; then - echo "Correcting permissions on /app/data..." - chown -R bun:bun /app/data +if [ "$(id -u)" = "0" ]; then + # Check if /app/data exists and is not owned by the bun user (UID 1000) + if [ -d "/app/data" ]; then + if [ "$(stat -c '%u' /app/data)" != "1000" ]; then + echo "Correcting permissions on /app/data..." + chown -R bun:bun /app/data + fi fi + # Run the CMD as the bun user + exec gosu bun "$@" +else + # Run the CMD directly if already running as non-root + exec "$@" fi - -# Run the CMD as the bun user -exec gosu bun "$@"