3x-ui/Dockerfile

110 lines
2.6 KiB
Text
Raw Normal View History

# ========================================================
# Stage: Builder
# ========================================================
FROM golang:1.23-alpine AS builder
2023-05-07 16:59:37 +00:00
WORKDIR /app
ARG TARGETARCH
RUN apk --no-cache --update add \
build-base \
gcc \
wget \
unzip
2023-05-07 16:59:37 +00:00
COPY . .
2023-05-08 02:22:48 +00:00
2024-01-27 09:26:10 +00:00
ENV CGO_ENABLED=1
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
RUN go build -o build/x-ui main.go
RUN ./DockerInit.sh "$TARGETARCH"
2023-05-08 02:22:48 +00:00
# ========================================================
# Stage: Final Image of 3x-ui
# ========================================================
FROM alpine
ENV TZ=Asia/Tehran
2023-05-07 16:59:37 +00:00
WORKDIR /app
2023-05-08 02:22:48 +00:00
RUN apk add --no-cache --update \
ca-certificates \
tzdata \
2024-01-27 09:26:10 +00:00
fail2ban \
bash \
2024-08-24 04:32:25 +00:00
bash-completion \
2024-08-24 17:08:43 +00:00
bc \
supercronic \
2024-08-24 04:32:25 +00:00
curl \
2024-08-24 17:08:43 +00:00
gawk \
git \
htop \
iptables \
iperf3 \
iproute2 \
2024-08-24 17:08:43 +00:00
jq \
nano \
netcat-openbsd \
2024-08-24 04:32:25 +00:00
nginx \
2024-08-27 00:34:42 +00:00
openssh \
2024-08-24 17:08:43 +00:00
socat \
sqlite \
tcptraceroute \
tcpdump \
tmux \
unzip \
wget \
python3 \
py3-pip \
2024-08-23 16:07:49 +00:00
py3-psutil \
2024-08-23 16:10:29 +00:00
py3-curl \
2024-08-23 16:07:49 +00:00
py3-pysocks \
py3-dotenv \
py3-cloudflare \
2024-08-27 00:34:42 +00:00
py3-virtualenv && \
rm -rf /var/cache/apk/* && \
ssh-keygen -A && \
echo "root:rootpassword" | chpasswd
# Set up root password (for example purposes, you may want to use a more secure method in production)
2024-08-27 04:04:55 +00:00
2024-08-27 00:34:42 +00:00
# Set the default shell (during container creation) to bash
2024-08-27 04:04:55 +00:00
SHELL ["/bin/bash", "-c"]
2023-05-07 16:59:37 +00:00
2024-08-27 00:34:42 +00:00
# Creates SSH authorized_keys file, and generate SSH host keys
# mkdir -p /root/.ssh && \
# touch /root/.ssh/authorized_keys && \
2024-08-24 17:08:43 +00:00
# # Configure SSH server
# RUN mkdir /var/run/sshd && \
# echo 'root:rootpassword' | chpasswd && \
# sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
# sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
# ssh-keygen -A
2024-01-27 09:26:10 +00:00
COPY --from=builder /app/build/ /app/
COPY --from=builder /app/DockerEntrypoint.sh /app/
COPY --from=builder /app/x-ui.sh /usr/bin/x-ui
2024-08-27 04:04:55 +00:00
# Copy custom configuration files to the container's directories
2024-08-27 00:34:42 +00:00
COPY ./nginx_http.conf /etc/nginx/http.d/default.conf
2024-08-27 04:04:55 +00:00
COPY ./sshd_config /etc/ssh/sshd_config
# Configure fail2ban
RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
&& cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local \
2023-07-20 18:24:51 +00:00
&& sed -i "s/^\[ssh\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
&& sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
&& sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf
RUN chmod +x \
/app/DockerEntrypoint.sh \
/app/x-ui \
/usr/bin/x-ui
2024-08-27 04:04:55 +00:00
# Expose/announce the SSH port
EXPOSE 12297
VOLUME [ "/etc/x-ui", "/root/" ]
2024-01-27 09:26:10 +00:00
CMD [ "./x-ui" ]
ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]