Skip to content

Commit 582d408

Browse files
committed
refactor: redesign Docker as pre-built image with env var config
- Rewrite Dockerfile to pre-install Xray and Nginx at build time - Xray installed via official install-release.sh - Nginx downloaded from project's custom build releases - Config templates copied from VLESS_reality/tls/xtls directories - Rewrite docker-entrypoint.sh to generate config from env vars - Supports reality/tls/xtls modes via MODE env var - Auto-generates UUID and Reality keys if not provided - Uses jq to modify JSON templates, envsubst for Nginx config - Starts services directly (exec xray), no systemd needed - Remove fake-systemctl (no longer needed) - Add nginx-tls.conf template for TLS mode - Simplify docker-compose.yml with env var configuration - Update all DOCKER.md docs (6 languages) for new approach - Update all README.md Docker sections (6 languages)
1 parent 3b334ae commit 582d408

16 files changed

Lines changed: 283 additions & 695 deletions

.dockerignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
.gitignore
44
.editorconfig
55
LICENSE
6-
README.md
7-
DOCKER.md
8-
*.md
96
po/
7+
translate.py
8+
translate_readme.py
109
Dockerfile
1110
docker-compose.yml
1211
docker-entrypoint.sh
1312
fake-systemctl
1413
.dockerignore
15-
translate.py
16-
translate_readme.py

DOCKER.md

Lines changed: 26 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,104 +2,62 @@
22

33
简体中文 | [English](/languages/en/DOCKER.md) | [Français](/languages/fr/DOCKER.md) | [Русский](/languages/ru/DOCKER.md) | [فارسی](/languages/fa/DOCKER.md) | [한국어](/languages/ko/DOCKER.md)
44

5-
本文档介绍如何使用 Docker 部署 Xray 一键脚本。
6-
7-
## 前提条件
8-
9-
* 已安装 Docker 和 Docker Compose
10-
* 服务器具备公网 IP
11-
* 安装 Reality 协议:需准备符合 Xray 要求的目标域名
12-
* 安装 TLS 版本:需准备域名并添加 A 记录
5+
本文档介绍如何使用 Docker 运行 Xray 一键脚本。镜像预装了 Xray 和 Nginx,容器内可直接使用原脚本的所有功能。
136

147
## 快速启动
158

16-
### 1. 克隆仓库
9+
### 1. 克隆仓库并构建
1710

1811
```bash
1912
git clone https://github.com/hello-yunshu/Xray_bash_onekey.git
2013
cd Xray_bash_onekey
14+
docker compose up -d
2115
```
2216

23-
### 2. 构建并启动容器
17+
### 2. 进入交互式安装菜单
2418

2519
```bash
26-
docker compose up -d
20+
docker attach xray-onekey
2721
```
2822

29-
### 3. 进入交互式安装菜单
23+
首次运行会自动启动安装脚本,按照提示完成配置即可。退出菜单后容器自动进入守护模式。
24+
25+
### 3. 后续管理
3026

3127
```bash
32-
docker attach xray-onekey
28+
docker exec -it xray-onekey idleleo
3329
```
3430

35-
首次运行时,容器会自动启动安装脚本,按照提示完成配置即可。
36-
3731
## 运行模式
3832

39-
容器支持以下运行模式:
40-
4133
| 模式 | 说明 | 命令 |
4234
|------|------|------|
43-
| `idleleo`(默认) | 启动服务并进入交互式管理菜单 | `docker compose up -d` |
44-
| `start` | 仅启动服务(守护模式) | 修改 `docker-compose.yml` 中的 `command: start` |
35+
| `idleleo`(默认) | 启动服务并进入管理菜单 | `docker compose up -d` + `docker attach xray-onekey` |
36+
| `start` | 仅启动服务(守护模式) | 修改 `docker-compose.yml` `command: start` |
4537
| `shell` | 启动服务并进入 Shell | `docker exec -it xray-onekey bash` |
4638

4739
## 管理操作
4840

49-
### 进入管理菜单
50-
51-
```bash
52-
docker exec -it xray-onekey idleleo
53-
```
54-
55-
### 查看服务状态
56-
57-
```bash
58-
docker exec -it xray-onekey systemctl status xray
59-
docker exec -it xray-onekey systemctl status nginx
60-
```
61-
62-
### 重启服务
63-
64-
```bash
65-
docker exec -it xray-onekey systemctl restart xray
66-
docker exec -it xray-onekey systemctl restart nginx
67-
```
68-
69-
### 查看客户端配置
70-
71-
```bash
72-
docker exec -it xray-onekey cat /etc/idleleo/info/xray_info.inf
73-
```
74-
75-
### 查看日志
41+
所有原脚本命令均可使用:
7642

7743
```bash
78-
docker exec -it xray-onekey cat /var/log/xray/access.log
79-
docker exec -it xray-onekey cat /var/log/xray/error.log
44+
docker exec -it xray-onekey idleleo # 管理菜单
45+
docker exec -it xray-onekey idleleo -s # 查看安装信息
46+
docker exec -it xray-onekey idleleo -x # 更新 Xray
47+
docker exec -it xray-onekey idleleo -n # 更新 Nginx
48+
docker exec -it xray-onekey idleleo -h # 查看帮助
8049
```
8150

82-
## 使用 docker run(替代 docker compose)
51+
## 使用 docker run
8352

8453
```bash
8554
docker build -t xray-onekey .
8655

87-
docker run -d --name xray-onekey \
88-
--network host \
89-
--cap-add NET_ADMIN \
90-
-e TZ=Asia/Shanghai \
91-
-v xray-conf:/etc/idleleo/conf \
92-
-v xray-cert:/etc/idleleo/cert \
93-
-v xray-info:/etc/idleleo/info \
94-
-v xray-logs:/var/log/xray \
95-
-v acme-data:/root/.acme.sh \
96-
-it xray-onekey
56+
docker run -d --name xray-onekey --network host --cap-add NET_ADMIN -e TZ=Asia/Shanghai -v xray-conf:/etc/idleleo/conf -v xray-cert:/etc/idleleo/cert -v xray-info:/etc/idleleo/info -v xray-logs:/var/log/xray -v acme-data:/root/.acme.sh -it xray-onekey
9757
```
9858

9959
## 数据持久化
10060

101-
容器使用 Docker Volume 保存数据,重建容器后配置不会丢失:
102-
10361
| Volume | 容器路径 | 说明 |
10462
|--------|---------|------|
10563
| `xray-conf` | `/etc/idleleo/conf` | Xray 和 Nginx 配置文件 |
@@ -108,13 +66,9 @@ docker run -d --name xray-onekey \
10866
| `xray-logs` | `/var/log/xray` | Xray 日志文件 |
10967
| `acme-data` | `/root/.acme.sh` | acme.sh 证书签发数据 |
11068

111-
## 自定义证书
112-
113-
`xray.crt``xray.key` 文件放入证书 Volume 对应的宿主机路径。使用 `docker volume inspect xray-cert` 查看宿主机路径。
114-
11569
## 网络配置
11670

117-
容器默认使用 `network_mode: host`即直接使用宿主机网络。这对 Xray 代理服务至关重要
71+
容器使用 `network_mode: host`直接使用宿主机网络
11872

11973
* Reality 模式需要看到真实客户端 IP
12074
* TLS 模式需要直接绑定 443/80 端口
@@ -123,30 +77,17 @@ docker run -d --name xray-onekey \
12377
## 注意事项
12478

12579
* 容器内使用 `fake-systemctl` 替代 systemd,`systemctl` 命令可正常使用
126-
* 防火墙建议在宿主机层面管理,而非容器内
127-
* 容器内置看门狗(watchdog),每 30 秒检查服务状态,异常时自动重启
80+
* 内置看门狗每 30 秒检查服务状态,异常时自动重启
81+
* 退出管理菜单后容器自动进入守护模式,服务不会中断
82+
* 防火墙建议在宿主机层面管理
12883
* 证书自动续签在容器内可正常工作(需确保 80 端口可访问)
129-
* 如需使用 fail2ban,可通过管理菜单安装
13084

13185
## 故障排查
13286

133-
### 容器无法启动
134-
135-
```bash
136-
docker logs xray-onekey
137-
```
138-
139-
### 服务未运行
140-
14187
```bash
142-
docker exec -it xray-onekey systemctl status xray
143-
docker exec -it xray-onekey systemctl start xray
144-
```
145-
146-
### 重新进入安装菜单
147-
148-
```bash
149-
docker exec -it xray-onekey idleleo
88+
docker logs xray-onekey # 查看容器日志
89+
docker exec -it xray-onekey bash # 进入容器
90+
docker exec -it xray-onekey idleleo -s # 查看安装信息
15091
```
15192

15293
### 完全重置

Dockerfile

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,77 @@
11
FROM debian:bookworm-slim
22

3+
ARG XRAY_VERSION=26.3.27
4+
ARG NGINX_BUILD_VERSION=2026.04.14
5+
36
ENV DEBIAN_FRONTEND=noninteractive
47

58
RUN apt-get update && apt-get install -y --no-install-recommends \
69
bc \
10+
ca-certificates \
11+
cron \
712
curl \
813
dbus \
14+
fail2ban \
15+
gettext \
916
git \
17+
gnupg \
18+
gzip \
19+
iftop \
20+
iptables \
21+
iptables-persistent \
1022
jq \
1123
lsof \
12-
python3 \
13-
qrencode \
14-
cron \
15-
gettext \
16-
socat \
24+
netcat-openbsd \
1725
nmap \
18-
iputils-ping \
19-
libpcre3 \
20-
libpcre3-dev \
21-
zlib1g \
22-
zlib1g-dev \
23-
iptables \
24-
iptables-persistent \
26+
openssl \
2527
procps \
2628
psmisc \
27-
ca-certificates \
28-
gnupg \
29+
python3 \
30+
qrencode \
31+
socat \
32+
sysvinit-utils \
2933
unzip \
30-
tar \
31-
gzip \
3234
vim \
33-
netcat-openbsd \
34-
sysvinit-utils \
3535
&& rm -rf /var/lib/apt/lists/*
3636

3737
RUN groupadd -f nogroup && \
3838
id nobody >/dev/null 2>&1 || useradd -g nogroup -s /usr/sbin/nologin nobody
3939

40-
RUN mkdir -p /etc/idleleo/conf/xray \
41-
/etc/idleleo/conf/nginx \
42-
/etc/idleleo/cert \
43-
/etc/idleleo/info \
44-
/etc/idleleo/logs \
45-
/etc/idleleo/tmp \
46-
/usr/local/bin \
47-
/usr/local/etc/xray \
48-
/usr/local/nginx \
49-
/var/log/xray \
50-
/var/spool/cron/crontabs
40+
RUN temp_dir=$(mktemp -d) && cd "$temp_dir" && \
41+
nginx_filename="xray-nginx-custom-$(dpkg --print-architecture).tar.gz" && \
42+
curl -L -o "$nginx_filename" "https://github.com/hello-yunshu/Xray_bash_onekey_Nginx/releases/download/v${NGINX_BUILD_VERSION}/$nginx_filename" && \
43+
tar -xzf "$nginx_filename" && \
44+
mv ./nginx /usr/local/nginx && \
45+
cd / && rm -rf "$temp_dir"
46+
47+
RUN curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh | bash -s -- install -f --version v${XRAY_VERSION} && \
48+
rm -f /usr/local/etc/xray/config.json
5149

5250
COPY fake-systemctl /usr/local/bin/systemctl
5351
RUN chmod +x /usr/local/bin/systemctl
5452

55-
COPY docker-entrypoint.sh /docker-entrypoint.sh
56-
RUN chmod +x /docker-entrypoint.sh
57-
5853
WORKDIR /etc/idleleo
5954

6055
COPY . /etc/idleleo/
6156

6257
RUN ln -sf /etc/idleleo/install.sh /usr/bin/idleleo && \
6358
ln -sf /etc/idleleo/conf/xray/config.json /usr/local/etc/xray/config.json && \
64-
mkdir -p /root/.acme.sh && \
65-
chmod +x /etc/idleleo/install.sh /etc/idleleo/auto_update.sh /etc/idleleo/ssl_update.sh /etc/idleleo/fail2ban_manager.sh /etc/idleleo/file_manager.sh
59+
chmod +x /etc/idleleo/install.sh /etc/idleleo/auto_update.sh \
60+
/etc/idleleo/ssl_update.sh /etc/idleleo/fail2ban_manager.sh \
61+
/etc/idleleo/file_manager.sh && \
62+
mkdir -p /etc/idleleo/conf/xray /etc/idleleo/conf/nginx \
63+
/etc/idleleo/cert /etc/idleleo/info /etc/idleleo/logs \
64+
/etc/idleleo/tmp /var/log/xray /root/.acme.sh
6665

67-
RUN echo '* soft nofile 65536' >> /etc/security/limits.conf && \
66+
RUN mkdir -p /etc/systemd/system && \
67+
printf '[Unit]\nDescription=Xray Service\n[Service]\nType=simple\nExecStart=/usr/local/bin/xray run -config /etc/idleleo/conf/xray/config.json\n[Install]\nWantedBy=multi-user.target\n' > /etc/systemd/system/xray.service && \
68+
printf '[Unit]\nDescription=NGINX HTTP and reverse proxy server\n[Service]\nType=forking\nPIDFile=/usr/local/nginx/logs/nginx.pid\nExecStart=/usr/local/nginx/sbin/nginx\nExecReload=/usr/local/nginx/sbin/nginx -s reload\nExecStop=/bin/kill -s QUIT \\$MAINPID\n[Install]\nWantedBy=multi-user.target\n' > /etc/systemd/system/nginx.service && \
69+
echo '* soft nofile 65536' >> /etc/security/limits.conf && \
6870
echo '* hard nofile 65536' >> /etc/security/limits.conf
6971

72+
COPY docker-entrypoint.sh /docker-entrypoint.sh
73+
RUN chmod +x /docker-entrypoint.sh
74+
7075
EXPOSE 443 80
7176

7277
VOLUME ["/etc/idleleo/conf", "/etc/idleleo/cert", "/etc/idleleo/info", "/var/log/xray", "/root/.acme.sh"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bash <(curl -Ss https://raw.githubusercontent.com/hello-yunshu/Xray_bash_onekey/
4545

4646
## Docker 部署
4747

48-
支持使用 Docker 部署,详见 [Docker 部署指南](/DOCKER.md)
48+
支持使用 Docker 部署,镜像预装 Xray 和 Nginx,容器内可直接使用原脚本所有功能。详见 [Docker 部署指南](/DOCKER.md)
4949

5050
```bash
5151
git clone https://github.com/hello-yunshu/Xray_bash_onekey.git

0 commit comments

Comments
 (0)