From a69c3f300ca478c8f969cf1697eca6787271da32 Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:11:29 +1000 Subject: [PATCH] Fix Docker image to work with rootless Docker environments --- .dockerfiles/entrypoint.sh | 14 ++++++++++---- Dockerfile | 4 +--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.dockerfiles/entrypoint.sh b/.dockerfiles/entrypoint.sh index d4da611..a123ae4 100755 --- a/.dockerfiles/entrypoint.sh +++ b/.dockerfiles/entrypoint.sh @@ -1,9 +1,15 @@ #!/bin/sh -[ -n "${PUID}" ] && usermod -u "${PUID}" zs -[ -n "${PGID}" ] && groupmod -g "${PGID}" zs +if [ "$(id -u)" -eq 0 ]; then + [ -n "${PUID}" ] && usermod -u "${PUID}" nobody + [ -n "${PGID}" ] && groupmod -g "${PGID}" nobody +fi printf "Configuring zs...\n" -printf "Switching UID=%s and GID=%s\n" "${PUID}" "${PGID}" -exec su-exec zs:zs "$@" +if [ "$(id -u)" -eq 0 ]; then + printf "Switching UID=%s and GID=%s\n" "$(id -u nobody)" "$(id -g nobody)" + exec su-exec nobody:nobody "$@" +else + exec zs "$@" +fi diff --git a/Dockerfile b/Dockerfile index 361133e..4c5929f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,9 +50,7 @@ RUN apk --no-cache -U add su-exec shadow tzdata ca-certificates curl jq ENV PUID=1000 ENV PGID=1000 -RUN addgroup -g "${PGID}" zs && \ - adduser -D -H -G zs -h /var/empty -u "${PUID}" zs && \ - mkdir -p /data && chown -R zs:zs /data +RUN mkdir -p /data && chown -R nobody:nobody /data EXPOSE 8000/tcp