FROM ymlisoft/kkfileview USER root # 安装工具 RUN apt-get update && apt-get install -y \ nginx \ apache2-utils \ xvfb \ net-tools \ curl \ && rm -rf /var/lib/apt/lists/* ENV SERVER_PORT=8012 ENV KKFILEVIEW_SECURITY_TRUST_HOST=default ENV AUTH_USERNAME=admin ENV AUTH_PASSWORD=yourpassword # Nginx 配置 RUN rm -rf /etc/nginx/sites-enabled/* && \ rm -rf /etc/nginx/conf.d/* && \ printf 'server {\n\ listen 7860 default_server;\n\ server_name _;\n\ \n\ # 密码保护\n\ auth_basic "Restricted Access";\n\ auth_basic_user_file /etc/nginx/.htpasswd;\n\ \n\ client_max_body_size 500M;\n\ \n\ location / {\n\ proxy_pass http://127.0.0.1:8012;\n\ proxy_set_header Host $http_host;\n\ proxy_set_header X-Real-IP $remote_addr;\n\ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;\n\ proxy_buffering off;\n\ }\n\ }\n' > /etc/nginx/conf.d/kkfileview.conf # 启动脚本 RUN printf '#!/bin/bash\n\ set -e\n\ \n\ echo "=== Starting Secure kkFileView ==="\n\ \n\ # 1. 找启动脚本路径\n\ STARTUP_SCRIPT=$(find /opt -name "startup.sh" -o -name "kkFileView" | grep "bin/" | head -n 1)\n\ KK_ROOT_DIR=$(dirname $(dirname "$STARTUP_SCRIPT"))\n\ echo "Found root dir: $KK_ROOT_DIR"\n\ \n\ # 2. 配置密码\n\ htpasswd -cb /etc/nginx/.htpasswd "$AUTH_USERNAME" "$AUTH_PASSWORD"\n\ \n\ # 3. 启动 Xvfb\n\ Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 &\n\ export DISPLAY=:99\n\ sleep 2\n\ \n\ # 4. 启动 kkFileView\n\ echo "Starting kkFileView on port 8012..."\n\ if [[ "$STARTUP_SCRIPT" == *".sh" ]]; then\n\ bash "$STARTUP_SCRIPT" &\n\ else\n\ "$STARTUP_SCRIPT" --server.port=8012 &\n\ fi\n\ \n\ # 5. 追踪真实日志文件\n\ # kkFileView 启动后会创建 log/kkFileView.log\n\ echo "Waiting for log file..."\n\ LOG_FILE="$KK_ROOT_DIR/log/kkFileView.log"\n\ \n\ # 循环等待日志文件生成\n\ for i in {1..30}; do\n\ if [ -f "$LOG_FILE" ]; then\n\ echo "✓ Found log file: $LOG_FILE"\n\ # 启动后台 tail 进程显示日志\n\ tail -f "$LOG_FILE" &\n\ break\n\ fi\n\ sleep 1\n\ done\n\ \n\ # 6. 等待端口就绪\n\ echo "Waiting for backend port 8012..."\n\ for i in {1..60}; do\n\ if netstat -tuln | grep ":8012 " > /dev/null; then\n\ echo "✓ Port 8012 is ready!"\n\ break\n\ fi\n\ echo "Waiting... ($i/60)"\n\ sleep 2\n\ done\n\ \n\ # 7. 启动 Nginx\n\ echo "Starting Nginx on 7860..."\n\ nginx -g "daemon off;"\n' > /start.sh && \ chmod +x /start.sh EXPOSE 7860 ENTRYPOINT [] CMD ["/start.sh"]