huanbao commited on
Commit
72fc036
·
verified ·
1 Parent(s): 5459210

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -97
Dockerfile CHANGED
@@ -1,104 +1,30 @@
1
- FROM ghcr.io/fish2018/pansou-web:latest
2
- USER root
3
 
4
- # 创建必要的目录并设置权限
5
- RUN mkdir -p /var/cache/nginx/client_temp \
6
- /var/cache/nginx/proxy_temp \
7
- /var/cache/nginx/fastcgi_temp \
8
- /var/cache/nginx/uwsgi_temp \
9
- /var/cache/nginx/scgi_temp \
10
- /var/run \
11
- /var/log/nginx \
12
- /app/cache && \
13
- chmod -R 777 /var/cache/nginx \
14
- /var/run \
15
- /var/log/nginx \
16
- /app/cache
17
 
18
- # 删除所有默认的 nginx 配置
19
- RUN rm -f /etc/nginx/conf.d/*.conf /etc/nginx/sites-enabled/* /etc/nginx/sites-available/* 2>/dev/null || true
 
20
 
21
- # 创建全新的 nginx 配置文件
22
- RUN cat > /etc/nginx/conf.d/pansou.conf <<'EOF'
23
- server {
24
- listen 7860 default_server;
25
- server_name _;
26
-
27
- # 前端静态文件
28
- root /app/frontend/dist;
29
- index index.html;
30
-
31
- # 前端路由
32
- location / {
33
- try_files $uri $uri/ /index.html;
34
- }
35
-
36
- # API 代理到后端
37
- location /api/ {
38
- proxy_pass http://127.0.0.1:8888;
39
- proxy_set_header Host $host;
40
- proxy_set_header X-Real-IP $remote_addr;
41
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
42
- proxy_set_header X-Forwarded-Proto $scheme;
43
- proxy_connect_timeout 30s;
44
- proxy_send_timeout 30s;
45
- proxy_read_timeout 30s;
46
- }
47
- }
48
- EOF
49
 
50
- # 修改 nginx 主配置
51
- RUN sed -i 's/^user\s/#user /g' /etc/nginx/nginx.conf && \
52
- sed -i 's|pid\s*/var/run/nginx.pid;|pid /tmp/nginx.pid;|g' /etc/nginx/nginx.conf
53
-
54
- # 验证配置内容
55
- RUN echo "=== Nginx config check ===" && \
56
- cat /etc/nginx/conf.d/pansou.conf && \
57
- echo "=== End of config ===" && \
58
- ls -la /etc/nginx/conf.d/
59
-
60
- # 创建启动脚本
61
- RUN cat > /start.sh <<'EOF'
62
- #!/bin/sh
63
- set -e
64
-
65
- echo "=== Starting PanSou Service ==="
66
-
67
- # 显示前端文件
68
- echo "Checking frontend files..."
69
- ls -la /app/frontend/dist/ | head -10
70
-
71
- # 显示 nginx 配置
72
- echo "Nginx configuration:"
73
- cat /etc/nginx/conf.d/pansou.conf
74
-
75
- echo "Starting PanSou backend service..."
76
- # 启动后端 API 服务(后台运行)
77
- cd /app && ./pansou &
78
-
79
- # 等待后端服务启动
80
- echo "Waiting for backend to start..."
81
- sleep 3
82
-
83
- # 检查后端是否启动
84
- if ! curl -s http://localhost:8888/api/health > /dev/null 2>&1; then
85
- echo "Warning: Backend service may not be running properly"
86
- else
87
- echo "Backend service started successfully on port 8888"
88
- fi
89
-
90
- # 测试 nginx 配置
91
- echo "Testing nginx configuration..."
92
- nginx -t
93
-
94
- echo "Starting Nginx on port 7860..."
95
- echo "Frontend root: /app/frontend/dist"
96
- # 启动 nginx(前台运行)
97
- exec nginx -g "daemon off;"
98
- EOF
99
 
100
- RUN chmod +x /start.sh
 
 
101
 
 
102
  EXPOSE 7860
103
- USER 1000
104
- CMD ["/start.sh"]
 
 
1
+ # 使用原始镜像作为基础
2
+ FROM ghcr.io/fish2018/spansou-web
3
 
4
+ # 环境变量配置
5
+ ENV TZ=Asia/Shanghai
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ # 工作目录与文件复制
8
+ WORKDIR /app
9
+ COPY start.sh /app/start.sh
10
 
11
+ # 安装coreutils并设置权限,添加用户映射
12
+ RUN apk add --no-cache coreutils && \
13
+ echo "pansou:x:1000:1000:pansou user:/app:/sbin/nologin" >> /etc/passwd && \
14
+ chmod +x /app/start.sh /app/pansou && \
15
+ mkdir -p /data/pansou_data /data/pansou_logs && \
16
+ chown -R 1000:1000 /app /data/pansou_data /data/pansou_logs && \
17
+ chmod 755 /data/pansou_data /data/pansou_logs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ # 以UID 1000运行
20
+ USER 1000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ # 健康检查(120秒间隔)
23
+ HEALTHCHECK --interval=120s --timeout=10s --start-period=30s --retries=3 \
24
+ CMD curl -f -m 2 http://127.0.0.1:8888/api/health || exit 1
25
 
26
+ # 暴露端口
27
  EXPOSE 7860
28
+
29
+ # 启动配置
30
+ CMD ["/app/start.sh"]