1
0

Dockerfile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # ========================================================
  2. # Stage: Builder
  3. # ========================================================
  4. FROM golang:1.25-alpine AS builder
  5. WORKDIR /app
  6. ARG TARGETARCH
  7. RUN apk --no-cache --update add \
  8. build-base \
  9. gcc \
  10. curl \
  11. unzip
  12. COPY . .
  13. ENV CGO_ENABLED=1
  14. ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
  15. RUN go build -ldflags "-w -s" -o build/x-ui main.go
  16. RUN ./DockerInit.sh "$TARGETARCH"
  17. # ========================================================
  18. # Stage: Final Image of 3x-ui
  19. # ========================================================
  20. FROM alpine
  21. ENV TZ=Asia/Tehran
  22. WORKDIR /app
  23. RUN apk add --no-cache --update \
  24. ca-certificates \
  25. tzdata \
  26. fail2ban \
  27. bash \
  28. curl \
  29. openssl
  30. COPY --from=builder /app/build/ /app/
  31. COPY --from=builder /app/DockerEntrypoint.sh /app/
  32. COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
  33. # Configure fail2ban
  34. RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
  35. && cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local \
  36. && sed -i "s/^\[ssh\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  37. && sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  38. && sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
  39. RUN chmod +x \
  40. /app/DockerEntrypoint.sh \
  41. /app/x-ui \
  42. /usr/bin/x-ui
  43. ENV XUI_ENABLE_FAIL2BAN="true"
  44. EXPOSE 2053
  45. VOLUME [ "/etc/x-ui" ]
  46. CMD [ "./x-ui" ]
  47. ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]