Trying to build discovery server via a Dockerfile however build file is failing.

So I’ve usually used the git repo GitHub - syncthing/syncthing: Open Source Continuous File Synchronization as my source and from the repository I usually build my discovery server. I’ve been doing this for many years with version 1.x however now with version 2 it seems the process is different.

Within the git sources there is a file Dockerfile.stdiscosrv. This dockerfile is really a lot different from what I previously used. For reference the contents of the Dockerfile.stdiscosrv are shown below:

ARG GOVERSION=latest
FROM golang:$GOVERSION AS builder
ARG BUILD_USER
ARG BUILD_HOST
ARG TARGETARCH
WORKDIR /src
COPY . .
ENV CGO_ENABLED=0
RUN if [ ! -f stdiscosrv-linux-$TARGETARCH ] ; then go run build.go -no-upgrade build stdiscosrv ; mv stdiscosrv stdiscosrv-linux-$TARGETARCH ; fi
FROM alpine
ARG TARGETARCH
LABEL org.opencontainers.image.authors=“The Syncthing Project” org.opencontainers.image.url=“https://syncthing.net” org.opencontainers.image.documentation=“https://docs.syncthing.net” org.opencontainers.image.source=“https://github.com/syncthing/syncthing” org.opencontainers.image.vendor=“The Syncthing Project” org.opencontainers.image.licenses=“MPL-2.0” org.opencontainers.image.title=“Syncthing Discovery Server”
EXPOSE 19200 8443
VOLUME [“/var/stdiscosrv”]
RUN apk add --no-cache ca-certificates su-exec
COPY --from=builder /src/stdiscosrv-linux-$TARGETARCH /bin/stdiscosrv
COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh
ENV PUID=1000 PGID=1000 HOME=/var/stdiscosrv
HEALTHCHECK --interval=1m --timeout=10s CMD nc -z localhost 8443 || exit 1
WORKDIR /var/stdiscosrvENTRYPOINT [“/bin/entrypoint.sh”, “/bin/stdiscosrv”]

So I just tried building the stdiscosrv using this exact dockerfile. The only thing I changed was the puid and pgid to 10000. In attempting to build I’m getting the following error however:


[disco builder 4/4] RUN if [ ! -f stdiscosrv-linux-amd64 ] ; then     go run build.go -no-upgrade build stdiscosrv ;     mv stdiscosrv stdiscosrv-linux-amd64 ;   fi:2.052 stat build.go: no such file or directory2.055 mv: cannot stat ‘stdiscosrv’: No such file or directory

failed to solve: process “/bin/sh -c if [ ! -f stdiscosrv-linux-$TARGETARCH ] ; then     go run build.go -no-upgrade build stdiscosrv ;     mv stdiscosrv stdiscosrv-linux-$TARGETARCH ;   fi” did not complete successfully: exit code: 1

It’s possible I don’t really know what I’m doing with this multistage build, however

Yeah, unclear, this works for me out of the box:

% docker build -t stdiscosrv:test -f Dockerfile.stdiscosrv .
...
% docker run -it --rm stdiscosrv:test --version
stdiscosrv v2.0.9-dev.7.g3382ccc3 "Hafnium Hornet" (go1.25.1 linux-arm64) root@buildkitsandbox 2025-09-12 09:41:47 UTC [noupgrade]

I’ll try something else, I’m not sure what the issue is really here.