# Build stage: Go 1.26 on Alpine for rclone
FROM golang:alpine AS builder
ARG CGO_ENABLED=0
WORKDIR /go/src/github.com/rclone/rclone/
RUN echo "**** Set Go Environment Variables ****" && \
go env -w GOCACHE=/root/.cache/go-build
# Install build dependencies
RUN echo "**** Install Build Dependencies ****" && \
apk add --no-cache \
make \
bash \
gawk \
git
# Download Go modules first to leverage cached layers
COPY go.mod .
COPY go.sum .
RUN echo "**** Download Go Dependencies ****" && \
go mod download -x
RUN echo "**** Verify Go Dependencies ****" && \
go mod verify
# Copy the rest of the source code
COPY . .
# Build the binary
RUN --mount=type=cache,target=/root/.cache/go-build,sharing=locked \
echo "**** Build Binary ****" && \
make
RUN echo "**** Print Version Binary ****" && \
./rclone version
# Final runtime image
FROM alpine:3.23.3
# Runtime dependencies
RUN echo "**** Install Runtime Dependencies ****" && \
apk add --no-cache \
ca-certificates \
fuse3 \
tzdata && \
echo "Enable user_allow_other in fuse" >> /etc/fuse.conf
# Copy the built binary from the builder
COPY --from=builder /go/src/github.com/rclone/rclone/rclone /usr/local/bin/
# Create non-root user to run the binary
RUN addgroup -g 1009 rclone && adduser -u 1009 -Ds /bin/sh -G rclone rclone
# Run as non-root user by default
USER rclone
ENTRYPOINT ["rclone"]
WORKDIR /data
ENV XDG_CONFIG_HOME=/config