Dockerfile 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. COPY --from=builder /app/build/ /app/
  30. COPY --from=builder /app/DockerEntrypoint.sh /app/
  31. COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
  32. # Configure fail2ban
  33. RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
  34. && cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local \
  35. && sed -i "s/^\[ssh\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  36. && sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  37. && sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
  38. RUN chmod +x \
  39. /app/DockerEntrypoint.sh \
  40. /app/x-ui \
  41. /usr/bin/x-ui
  42. ENV XUI_ENABLE_FAIL2BAN="true"
  43. EXPOSE 2053
  44. VOLUME [ "/etc/x-ui" ]
  45. CMD [ "./x-ui" ]
  46. ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]