Dockerfile 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # ========================================================
  2. # Stage: Frontend (Vite)
  3. # ========================================================
  4. FROM --platform=$BUILDPLATFORM node:22-alpine AS frontend
  5. WORKDIR /src/frontend
  6. COPY frontend/package.json frontend/package-lock.json ./
  7. RUN npm ci
  8. COPY frontend/ ./
  9. COPY web/translation /src/web/translation
  10. RUN npm run build
  11. # ========================================================
  12. # Stage: Builder
  13. # ========================================================
  14. FROM golang:1.26-alpine AS builder
  15. WORKDIR /app
  16. ARG TARGETARCH
  17. RUN apk --no-cache --update add \
  18. build-base \
  19. gcc \
  20. curl \
  21. unzip
  22. COPY . .
  23. COPY --from=frontend /src/web/dist ./web/dist
  24. ENV CGO_ENABLED=1
  25. ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
  26. RUN go build -ldflags "-w -s" -o build/x-ui main.go
  27. RUN ./DockerInit.sh "$TARGETARCH"
  28. # ========================================================
  29. # Stage: Final Image of 3x-ui
  30. # ========================================================
  31. FROM alpine
  32. ENV TZ=Asia/Tehran
  33. WORKDIR /app
  34. RUN apk add --no-cache --update \
  35. ca-certificates \
  36. tzdata \
  37. fail2ban \
  38. bash \
  39. curl \
  40. openssl
  41. COPY --from=builder /app/build/ /app/
  42. COPY --from=builder /app/DockerEntrypoint.sh /app/
  43. COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
  44. COPY --from=builder /app/web/translation /app/web/translation
  45. # Configure fail2ban
  46. RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
  47. && cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local \
  48. && sed -i "s/^\[ssh\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  49. && sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
  50. && sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
  51. RUN chmod +x \
  52. /app/DockerEntrypoint.sh \
  53. /app/x-ui \
  54. /usr/bin/x-ui
  55. ENV XUI_ENABLE_FAIL2BAN="true"
  56. # Database backend: set XUI_DB_TYPE=postgres and XUI_DB_DSN=postgres://... to use PostgreSQL.
  57. # Default (unset) is SQLite stored under /etc/x-ui.
  58. ENV XUI_DB_TYPE=""
  59. ENV XUI_DB_DSN=""
  60. EXPOSE 2053
  61. VOLUME [ "/etc/x-ui" ]
  62. CMD [ "./x-ui" ]
  63. ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]