pans / Dockerfile
jxdn123's picture
Update Dockerfile
d3fce70 verified
FROM ghcr.io/fish2018/pansou-web:latest
ENV ENABLED_PLUGINS="labi,zhizhen,shandian,duoduo,muou,wanou"
USER root
# 创建必要的目录并设置权限
RUN mkdir -p /var/cache/nginx/client_temp \
/var/cache/nginx/proxy_temp \
/var/cache/nginx/fastcgi_temp \
/var/cache/nginx/uwsgi_temp \
/var/cache/nginx/scgi_temp \
/var/run \
/var/log/nginx \
/app/cache && \
chmod -R 777 /var/cache/nginx \
/var/run \
/var/log/nginx \
/app/cache
# 删除所有默认的 nginx 配置
RUN rm -f /etc/nginx/conf.d/*.conf /etc/nginx/sites-enabled/* /etc/nginx/sites-available/* 2>/dev/null || true
# 创建全新的 nginx 配置文件
RUN cat > /etc/nginx/conf.d/pansou.conf <<'EOF'
server {
listen 7860 default_server;
server_name _;
# 前端静态文件
root /app/frontend/dist;
index index.html;
# 前端路由
location / {
try_files $uri $uri/ /index.html;
}
# API 代理到后端
location /api/ {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
}
EOF
# 修改 nginx 主配置
RUN sed -i 's/^user\s/#user /g' /etc/nginx/nginx.conf && \
sed -i 's|pid\s*/var/run/nginx.pid;|pid /tmp/nginx.pid;|g' /etc/nginx/nginx.conf
# 验证配置内容
RUN echo "=== Nginx config check ===" && \
cat /etc/nginx/conf.d/pansou.conf && \
echo "=== End of config ===" && \
ls -la /etc/nginx/conf.d/
# 创建启动脚本
RUN cat > /start.sh <<'EOF'
#!/bin/sh
set -e
echo "=== Starting PanSou Service ==="
# 显示前端文件
echo "Checking frontend files..."
ls -la /app/frontend/dist/ | head -10
# 显示 nginx 配置
echo "Nginx configuration:"
cat /etc/nginx/conf.d/pansou.conf
echo "Starting PanSou backend service..."
# 启动后端 API 服务(后台运行)
cd /app && ./pansou &
# 等待后端服务启动
echo "Waiting for backend to start..."
sleep 3
# 检查后端是否启动
if ! curl -s http://localhost:8888/api/health > /dev/null 2>&1; then
echo "Warning: Backend service may not be running properly"
else
echo "Backend service started successfully on port 8888"
fi
# 测试 nginx 配置
echo "Testing nginx configuration..."
nginx -t
echo "Starting Nginx on port 7860..."
echo "Frontend root: /app/frontend/dist"
# 启动 nginx(前台运行)
exec nginx -g "daemon off;"
EOF
RUN chmod +x /start.sh
EXPOSE 7860
USER 1000
CMD ["/start.sh"]