Skip to content

Instantly share code, notes, and snippets.

@sthalik
Created February 18, 2026 15:57
Show Gist options
  • Select an option

  • Save sthalik/72ec341f89355e87f7c5d3406d0ae858 to your computer and use it in GitHub Desktop.

Select an option

Save sthalik/72ec341f89355e87f7c5d3406d0ae858 to your computer and use it in GitHub Desktop.
FROM alpine:latest AS builder

RUN \
set -euo pipefail; \
set +x; \
apk --no-cache add samba-server samba-common-tools lddtree >/dev/null; \
apk --no-cache info -q | grep samba \
| xargs apk --no-cache info -qL | grep . | uniq -u \
| xargs sh -c 'set -eu; for i in "$@"; do case "$i" in usr/lib/*|lib/*) echo /$i;; esac; done' \
| LD_LIBRARY_PATH=/usr/lib/samba xargs lddtree -l \
| awk '{if (!count[$0]++) print $0}' \
| xargs sh -c 'set -eu; for i in "$@" /usr/sbin/smbd; do d=/stub/$(dirname $i); mkdir -p $d; cp -d $i $d/.; done'; \
mkdir -p /stub/etc/ssl/certs; \
cp -L /etc/ssl/certs/ca-certificates.crt /stub/etc/ssl/certs; \
dirs="/stub/var/log/samba /stub/var/cache/samba /stub/var/lib/samba/private /stub/etc/samba /stub/var/run/samba"; \
for dir in $dirs; do mkdir -m0770 -p $dir; chown root:6001 $dir; done; \
echo xferd:x:6001:6001::/:/usr/bin/nologin >> /etc/passwd; \
echo xferd:x:6001: >> /etc/group;

FROM scratch AS final
LABEL org.opencontainers.image.title="samba"
COPY --from=builder /stub /
ENTRYPOINT ["/usr/sbin/smbd", "-F", "--no-process-group"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment