From 62fc77f48c34b27b41556062b9951a4fedf71301 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Apr 2026 22:44:39 -0500 Subject: add directive to enable heredoc --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Dockerfile') diff --git a/Dockerfile b/Dockerfile index 499b0135..d4ca4bb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,6 @@ +# syntax=docker/dockerfile:1 +# ^ enable heredoc for BuildKit + # build static web content # note: pin this to amd64 to speed it up, it is prohibitively slow under QEMU FROM --platform=$BUILDPLATFORM node:22-alpine AS web -- cgit v1.2.3 From 06b9b9d27ad378a59229bb31b4b94f2fc75c66db Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Apr 2026 22:44:52 -0500 Subject: install gosu --- Dockerfile | 1 + 1 file changed, 1 insertion(+) (limited to 'Dockerfile') diff --git a/Dockerfile b/Dockerfile index d4ca4bb6..0beebcb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,6 +46,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ jq \ wget \ tini \ + gosu \ && \ rm -rf \ /tmp/* \ -- cgit v1.2.3 From b7d23af65b7c67128a17c72025a996050b70751f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Apr 2026 22:45:14 -0500 Subject: add slskd user/group --- Dockerfile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Dockerfile') diff --git a/Dockerfile b/Dockerfile index 0beebcb0..c28e15d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,10 +54,16 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ /var/cache/apt/* \ /var/tmp/* -RUN bash -c 'mkdir -p /app/{incomplete,downloads} \ - && chmod -R 777 /app \ +# remove the default 'ubuntu' user that occupies 1000:1000 +# and replace it with our own slskd user/group +RUN userdel -r ubuntu && \ + groupadd -g 1000 slskd && \ + useradd -u 1000 -g slskd -d /app -s /sbin/nologin slskd + +RUN bash -c 'mkdir -p /app/{incomplete,downloads} \ + && chown -R slskd:slskd /app \ && mkdir -p /.net \ - && chmod 777 /.net' + && chown slskd:slskd /.net' VOLUME /app -- cgit v1.2.3 From a278bdb398a4a54057c3454b292ff887e298c049 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Apr 2026 22:45:34 -0500 Subject: add script --- Dockerfile | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 5 deletions(-) (limited to 'Dockerfile') diff --git a/Dockerfile b/Dockerfile index c28e15d2..1f1cc149 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,7 +74,7 @@ ENV SHELL=/usr/bin/bash \ DOTNET_BUNDLE_EXTRACT_BASE_DIR=/.net \ DOTNET_gcServer=0 \ DOTNET_gcConcurrent=1 \ - DOTNET_GCHeapHardLimit=0x80000000 \ + DOTNET_GCHeapHardLimit=0x80000000 \ DOTNET_GCConserveMemory=9 \ SLSKD_UMASK=0022 \ SLSKD_HTTP_PORT=5030 \ @@ -101,7 +101,82 @@ LABEL org.opencontainers.image.title=slskd \ WORKDIR /slskd COPY --from=publish /slskd/dist/${TARGETPLATFORM} . -RUN echo "umask \$SLSKD_UMASK && ./slskd" > start.sh \ - && chmod +x start.sh - -ENTRYPOINT ["/usr/bin/tini", "--", "./start.sh"] +# supports two modes: +# 1. PUID/PGID (legacy linuxserver style) — container starts as root, +# mutates user, chowns /app if needed, drops privileges via gosu. +# 2. --user / user: (modern Docker) — container starts as non-root, +# skips all usermod/chown, execs the app directly. +COPY <<'SCRIPT' /entrypoint.sh + +#!/bin/bash +set -e + +# --user mode; user has provided a user via the command line or docker compose file +#--------------------------------------------------------------------------------------- +if [ "$(id -u)" -ne 0 ]; then + # if the user has also supplied PUID or PGID, let them know they need to use one or the other + if [ -n "${PUID}" ] || [ -n "${PGID}" ]; then + echo "ERROR: PUID/PGID are set but the container is running as a non-root user (using --user or user:)." + echo "Use one or the other, not both. Remove --user and set PUID/PGID, or remove PUID/PGID and use --user." + exit 1 + fi + + # exit if /app is not writable + if [ ! -r /app ] || [ ! -w /app ]; then + echo "ERROR: /app is not readable and/or writable by the current user ($(id -u):$(id -g))." + echo "When using --user, ensure the mounted directory is readable and writable by UID $(id -u)." + exit 1 + fi + + # set umask and launch + umask "$SLSKD_UMASK" + exec "$@" +fi + +# PUID/PGID mode; user has provided explicit user and group IDs to use +#--------------------------------------------------------------------------------------- +PUID="${PUID:-1000}" +PGID="${PGID:-1000}" + +if ! [[ "${PUID}" =~ ^[0-9]+$ ]]; then + echo "ERROR: PUID must be a non-negative integer, got '${PUID}'." + exit 1 +fi + +if ! [[ "${PGID}" =~ ^[0-9]+$ ]]; then + echo "ERROR: PGID must be a non-negative integer, got '${PGID}'." + exit 1 +fi + +# update group +current_gid=$(getent group slskd | cut -d: -f3) +echo "[entrypoint] current GID: ${current_gid}" +if [ "${current_gid}" != "${PGID}" ]; then + groupmod -o -g "${PGID}" slskd + usermod -g "${PGID}" slskd + echo "[entrypoint] new GID: ${PGID}" +fi + +# update user +current_uid=$(id -u slskd 2>/dev/null || echo "") +echo "[entrypoint] current UID: ${current_uid}" +if [ "${current_uid}" != "${PUID}" ]; then + usermod -o -u "${PUID}" slskd + echo "[entrypoint] new UID: ${PUID}" +fi + +# change owner of the directories we need to write +chown -R "${PUID}:${PGID}" /app +chown "${PUID}:${PGID}" /.net + +# set umask and launch +umask "$SLSKD_UMASK" +exec gosu "${PUID}:${PGID}" "$@" + +SCRIPT +# EOF + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/usr/bin/tini", "--", "/entrypoint.sh"] +CMD ["./slskd"] \ No newline at end of file -- cgit v1.2.3