Dockerfile 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # ========================================================
  2. # Stage: Builder
  3. # ========================================================
  4. FROM golang:1.22-alpine AS builder
  5. WORKDIR /app
  6. ARG TARGETARCH
  7. RUN apk --no-cache --update add \
  8. build-base \
  9. gcc \
  10. wget \
  11. unzip
  12. COPY . .
  13. ENV CGO_ENABLED=1
  14. ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
  15. RUN go build -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. COPY --from=builder /app/build/ /app/
  29. COPY --from=builder /app/DockerEntrypoint.sh /app/
  30. COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
  31. # Configure fail2ban
  32. RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
  33. && cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local \
  34. && sed -i "s/^\[ssh\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  35. && sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  36. && sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
  37. RUN chmod +x \
  38. /app/DockerEntrypoint.sh \
  39. /app/x-ui \
  40. /usr/bin/x-ui
  41. VOLUME [ "/etc/x-ui" ]
  42. CMD [ "./x-ui" ]
  43. ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]