devin15 commited on
Commit
c6a66d4
·
verified ·
1 Parent(s): 8af1fcc

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +87 -4
Dockerfile CHANGED
@@ -102,6 +102,30 @@ RUN cd /tmp && \
102
  # 屏蔽警告?: nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
103
  # RUN echo 'user nginx;' > /etc/nginx/nginx.conf && \
104
  # echo 'worker_processes auto;' >> /etc/nginx/nginx.conf && \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  RUN echo 'worker_processes auto;' > /etc/nginx/nginx.conf && \
106
  echo 'error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf && \
107
  echo 'pid /var/run/nginx.pid;' >> /etc/nginx/nginx.conf && \
@@ -116,15 +140,35 @@ RUN echo 'worker_processes auto;' > /etc/nginx/nginx.conf && \
116
  echo ' sendfile on;' >> /etc/nginx/nginx.conf && \
117
  echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf && \
118
  echo '' >> /etc/nginx/nginx.conf && \
 
 
 
 
119
  echo ' server {' >> /etc/nginx/nginx.conf && \
120
  echo ' listen 7860;' >> /etc/nginx/nginx.conf && \
121
  echo ' server_name localhost;' >> /etc/nginx/nginx.conf && \
 
 
122
  echo ' location / {' >> /etc/nginx/nginx.conf && \
123
  echo ' root /usr/share/nginx/html;' >> /etc/nginx/nginx.conf && \
124
  echo ' index index.html index.htm;' >> /etc/nginx/nginx.conf && \
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  echo ' }' >> /etc/nginx/nginx.conf && \
126
  echo ' }' >> /etc/nginx/nginx.conf && \
127
  echo '}' >> /etc/nginx/nginx.conf
 
128
  # # 创建nginx配置文件(修改端口为7860)
129
  # RUN cat > /etc/nginx/nginx.conf << 'EOF'
130
  # worker_processes auto;
@@ -199,6 +243,24 @@ RUN nginx -t && \
199
  # 暴露端口7860和443(HTTPS)
200
  EXPOSE 7860
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  # 创建启动脚本
203
  RUN echo '#!/bin/sh' > /start.sh && \
204
  echo 'echo "=== Container Starting ==="' >> /start.sh && \
@@ -211,13 +273,34 @@ RUN echo '#!/bin/sh' > /start.sh && \
211
  echo 'echo "Testing nginx configuration..."' >> /start.sh && \
212
  echo 'nginx -t' >> /start.sh && \
213
  echo 'echo ""' >> /start.sh && \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  echo 'echo "Starting nginx on port 7860..."' >> /start.sh && \
215
- # echo 'exec gosu root nginx -g "daemon off;"' >> /start.sh && \ # hf不允许提权
216
- echo 'exec java -jar /app/app.jar > /app/app-run.log 2>&1 & ' >> /start.sh && \
217
- echo 'exec nginx -g "daemon on;" &' >> /start.sh && \
218
- echo 'exec tail -n 1000 -f /app/app-run.log' >> /start.sh && \
 
 
 
 
219
  chmod +x /start.sh
220
 
 
221
  # 设置工作目录
222
  WORKDIR /usr/share/nginx/html
223
  RUN unzip dist.zip
 
102
  # 屏蔽警告?: nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
103
  # RUN echo 'user nginx;' > /etc/nginx/nginx.conf && \
104
  # echo 'worker_processes auto;' >> /etc/nginx/nginx.conf && \
105
+ # RUN echo 'worker_processes auto;' > /etc/nginx/nginx.conf && \
106
+ # echo 'error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf && \
107
+ # echo 'pid /var/run/nginx.pid;' >> /etc/nginx/nginx.conf && \
108
+ # echo '' >> /etc/nginx/nginx.conf && \
109
+ # echo 'events {' >> /etc/nginx/nginx.conf && \
110
+ # echo ' worker_connections 1024;' >> /etc/nginx/nginx.conf && \
111
+ # echo '}' >> /etc/nginx/nginx.conf && \
112
+ # echo '' >> /etc/nginx/nginx.conf && \
113
+ # echo 'http {' >> /etc/nginx/nginx.conf && \
114
+ # echo ' include /etc/nginx/mime.types;' >> /etc/nginx/nginx.conf && \
115
+ # echo ' default_type application/octet-stream;' >> /etc/nginx/nginx.conf && \
116
+ # echo ' sendfile on;' >> /etc/nginx/nginx.conf && \
117
+ # echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf && \
118
+ # echo '' >> /etc/nginx/nginx.conf && \
119
+ # echo ' server {' >> /etc/nginx/nginx.conf && \
120
+ # echo ' listen 7860;' >> /etc/nginx/nginx.conf && \
121
+ # echo ' server_name localhost;' >> /etc/nginx/nginx.conf && \
122
+ # echo ' location / {' >> /etc/nginx/nginx.conf && \
123
+ # echo ' root /usr/share/nginx/html;' >> /etc/nginx/nginx.conf && \
124
+ # echo ' index index.html index.htm;' >> /etc/nginx/nginx.conf && \
125
+ # echo ' }' >> /etc/nginx/nginx.conf && \
126
+ # echo ' }' >> /etc/nginx/nginx.conf && \
127
+ # echo '}' >> /etc/nginx/nginx.conf
128
+ # 创建nginx配置文件(添加API反向代理)
129
  RUN echo 'worker_processes auto;' > /etc/nginx/nginx.conf && \
130
  echo 'error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf && \
131
  echo 'pid /var/run/nginx.pid;' >> /etc/nginx/nginx.conf && \
 
140
  echo ' sendfile on;' >> /etc/nginx/nginx.conf && \
141
  echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf && \
142
  echo '' >> /etc/nginx/nginx.conf && \
143
+ echo ' upstream backend {' >> /etc/nginx/nginx.conf && \
144
+ echo ' server 127.0.0.1:8081;' >> /etc/nginx/nginx.conf && \
145
+ echo ' }' >> /etc/nginx/nginx.conf && \
146
+ echo '' >> /etc/nginx/nginx.conf && \
147
  echo ' server {' >> /etc/nginx/nginx.conf && \
148
  echo ' listen 7860;' >> /etc/nginx/nginx.conf && \
149
  echo ' server_name localhost;' >> /etc/nginx/nginx.conf && \
150
+ echo '' >> /etc/nginx/nginx.conf && \
151
+ echo ' # 静态文件服务' >> /etc/nginx/nginx.conf && \
152
  echo ' location / {' >> /etc/nginx/nginx.conf && \
153
  echo ' root /usr/share/nginx/html;' >> /etc/nginx/nginx.conf && \
154
  echo ' index index.html index.htm;' >> /etc/nginx/nginx.conf && \
155
+ echo ' try_files $uri $uri/ /index.html;' >> /etc/nginx/nginx.conf && \
156
+ echo ' }' >> /etc/nginx/nginx.conf && \
157
+ echo '' >> /etc/nginx/nginx.conf && \
158
+ echo ' # API反向代理' >> /etc/nginx/nginx.conf && \
159
+ echo ' location /api/ {' >> /etc/nginx/nginx.conf && \
160
+ echo ' proxy_pass http://backend/;' >> /etc/nginx/nginx.conf && \
161
+ echo ' proxy_set_header Host $host;' >> /etc/nginx/nginx.conf && \
162
+ echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/nginx.conf && \
163
+ echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/nginx.conf && \
164
+ echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/nginx.conf && \
165
+ echo ' proxy_connect_timeout 30s;' >> /etc/nginx/nginx.conf && \
166
+ echo ' proxy_send_timeout 30s;' >> /etc/nginx/nginx.conf && \
167
+ echo ' proxy_read_timeout 30s;' >> /etc/nginx/nginx.conf && \
168
  echo ' }' >> /etc/nginx/nginx.conf && \
169
  echo ' }' >> /etc/nginx/nginx.conf && \
170
  echo '}' >> /etc/nginx/nginx.conf
171
+
172
  # # 创建nginx配置文件(修改端口为7860)
173
  # RUN cat > /etc/nginx/nginx.conf << 'EOF'
174
  # worker_processes auto;
 
243
  # 暴露端口7860和443(HTTPS)
244
  EXPOSE 7860
245
 
246
+ # 创建启动脚本
247
+ # RUN echo '#!/bin/sh' > /start.sh && \
248
+ # echo 'echo "=== Container Starting ==="' >> /start.sh && \
249
+ # echo 'echo "Java version:"' >> /start.sh && \
250
+ # echo 'java -version' >> /start.sh && \
251
+ # echo 'echo ""' >> /start.sh && \
252
+ # echo 'echo "Nginx version:"' >> /start.sh && \
253
+ # echo 'nginx -v' >> /start.sh && \
254
+ # echo 'echo ""' >> /start.sh && \
255
+ # echo 'echo "Testing nginx configuration..."' >> /start.sh && \
256
+ # echo 'nginx -t' >> /start.sh && \
257
+ # echo 'echo ""' >> /start.sh && \
258
+ # echo 'echo "Starting nginx on port 7860..."' >> /start.sh && \
259
+ # # echo 'exec gosu root nginx -g "daemon off;"' >> /start.sh && \ # hf不允许提权
260
+ # echo 'exec java -jar /app/app.jar > /app/app-run.log 2>&1 & ' >> /start.sh && \
261
+ # echo 'exec nginx -g "daemon on;" &' >> /start.sh && \
262
+ # echo 'exec tail -n 1000 -f /app/app-run.log' >> /start.sh && \
263
+ # chmod +x /start.sh
264
  # 创建启动脚本
265
  RUN echo '#!/bin/sh' > /start.sh && \
266
  echo 'echo "=== Container Starting ==="' >> /start.sh && \
 
273
  echo 'echo "Testing nginx configuration..."' >> /start.sh && \
274
  echo 'nginx -t' >> /start.sh && \
275
  echo 'echo ""' >> /start.sh && \
276
+ echo 'echo "Starting Java application on port 8081..."' >> /start.sh && \
277
+ echo 'java -jar /app/app.jar > /app/app-run.log 2>&1 &' >> /start.sh && \
278
+ echo 'JAVA_PID=$!' >> /start.sh && \
279
+ echo 'echo "Java application PID: $JAVA_PID"' >> /start.sh && \
280
+ echo '' >> /start.sh && \
281
+ echo '# 等待Java应用启动' >> /start.sh && \
282
+ echo 'echo "Waiting for Java application to start..."' >> /start.sh && \
283
+ echo 'for i in $(seq 1 30); do' >> /start.sh && \
284
+ echo ' if curl -f http://localhost:8081/actuator/health >/dev/null 2>&1; then' >> /start.sh && \
285
+ echo ' echo "Java application is ready!"' >> /start.sh && \
286
+ echo ' break' >> /start.sh && \
287
+ echo ' fi' >> /start.sh && \
288
+ echo ' echo "Waiting... ($i/30)"' >> /start.sh && \
289
+ echo ' sleep 2' >> /start.sh && \
290
+ echo 'done' >> /start.sh && \
291
+ echo '' >> /start.sh && \
292
  echo 'echo "Starting nginx on port 7860..."' >> /start.sh && \
293
+ echo 'nginx -g "daemon on;" &' >> /start.sh && \
294
+ echo 'NGINX_PID=$!' >> /start.sh && \
295
+ echo 'echo "Nginx PID: $NGINX_PID"' >> /start.sh && \
296
+ echo '' >> /start.sh && \
297
+ echo '# 监控两个进程' >> /start.sh && \
298
+ echo 'trap "kill $JAVA_PID $NGINX_PID; exit" TERM INT' >> /start.sh && \
299
+ echo 'tail -f /app/app-run.log &' >> /start.sh && \
300
+ echo 'wait' >> /start.sh && \
301
  chmod +x /start.sh
302
 
303
+
304
  # 设置工作目录
305
  WORKDIR /usr/share/nginx/html
306
  RUN unzip dist.zip