From d69d0158d8e5e83c7b93cddb54f13183dd4d74b9 Mon Sep 17 00:00:00 2001 From: Jeason <1710884619@qq.com> Date: Wed, 5 Nov 2025 13:32:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AB=AF=E5=8F=A3=E4=B8=BA74?= =?UTF-8?q?00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 +++--- Dockerfile.dev | 2 +- Dockerfile.low-mem | 6 +++--- README_DOCKER.md | 24 ++++++++++++------------ docker-compose.dev.yml | 2 +- docker-compose.low-mem.yml | 4 ++-- docker-compose.yml | 4 ++-- start_web.py | 6 +++--- web_app.py | 2 +- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index 276ed98..fa89cce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,14 +42,14 @@ RUN mkdir -p templates static/css static/js logs data models RUN chmod +x start_web.py # 暴露端口 -EXPOSE 5000 +EXPOSE 7400 # 健康检查 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD python -c "import requests; requests.get('http://localhost:5000/health')" || exit 1 + CMD python -c "import requests; requests.get('http://localhost:7400/health')" || exit 1 # 使用gunicorn启动应用(生产环境) # 注意:默认配置使用2个worker,适合1GB+内存的机器 # 如果机器内存较小(512MB-1GB),建议修改为 "--workers", "1" # 使用 python -m gunicorn 确保可以找到 gunicorn(即使可执行文件不在PATH中也能工作) -CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"] +CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:7400", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"] diff --git a/Dockerfile.dev b/Dockerfile.dev index c054627..3542425 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -31,7 +31,7 @@ COPY . . RUN mkdir -p templates static/css static/js logs data models # 暴露端口 -EXPOSE 5000 +EXPOSE 7400 # 开发模式:使用Flask开发服务器 CMD ["python", "start_web.py"] diff --git a/Dockerfile.low-mem b/Dockerfile.low-mem index 424a124..50a69cb 100644 --- a/Dockerfile.low-mem +++ b/Dockerfile.low-mem @@ -56,13 +56,13 @@ RUN mkdir -p templates static/css static/js logs data models RUN chmod +x start_web.py # 暴露端口 -EXPOSE 5000 +EXPOSE 7400 # 健康检查(不使用 requests,直接用 Python) HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ - CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:5000/health').read()" || exit 1 + CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7400/health').read()" || exit 1 # 使用gunicorn启动应用(小内存配置:单worker,减少内存占用) # 使用 python -m gunicorn 确保可以找到 gunicorn(即使可执行文件不在PATH中也能工作) -CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "--workers", "1", "--threads", "2", "--timeout", "120", "--worker-class", "sync", "--max-requests", "1000", "--max-requests-jitter", "100", "--preload", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"] +CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:7400", "--workers", "1", "--threads", "2", "--timeout", "120", "--worker-class", "sync", "--max-requests", "1000", "--max-requests-jitter", "100", "--preload", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"] diff --git a/README_DOCKER.md b/README_DOCKER.md index 4df1d63..5499a0c 100644 --- a/README_DOCKER.md +++ b/README_DOCKER.md @@ -46,7 +46,7 @@ docker build -t diet-recommendation-app . # 运行容器 docker run -d \ --name diet_recommendation_app \ - -p 5000:5000 \ + -p 7400:7400 \ -v $(pwd)/data:/app/data \ -v $(pwd)/logs:/app/logs \ -v $(pwd)/models:/app/models \ @@ -63,12 +63,12 @@ docker rm diet_recommendation_app ## 🌐 访问应用 容器启动后,访问: -- **主页**: http://localhost:5000 -- **背诵排序**: http://localhost:5000/recitation -- **数据采集**: http://localhost:5000/data-collection -- **智能推荐**: http://localhost:5000/recommendation -- **营养分析**: http://localhost:5000/analysis -- **健康检查**: http://localhost:5000/health +- **主页**: http://localhost:7400 +- **背诵排序**: http://localhost:7400/recitation +- **数据采集**: http://localhost:7400/data-collection +- **智能推荐**: http://localhost:7400/recommendation +- **营养分析**: http://localhost:7400/analysis +- **健康检查**: http://localhost:7400/health ## 📁 数据持久化 @@ -92,11 +92,11 @@ environment: ### 端口配置 -默认端口为 `5000`,如需修改: +默认端口为 `7400`,如需修改: ```yaml ports: - - "8080:5000" # 将主机的8080端口映射到容器的5000端口 + - "8080:7400" # 将主机的8080端口映射到容器的7400端口 ``` ## 🐛 故障排除 @@ -153,7 +153,7 @@ docker-compose ps docker ps ``` -健康检查端点:`http://localhost:5000/health` +健康检查端点:`http://localhost:7400/health` ## 🔒 安全建议 @@ -177,7 +177,7 @@ server { server_name your-domain.com; location / { - proxy_pass http://localhost:5000; + proxy_pass http://localhost:7400; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -246,7 +246,7 @@ services: - 标准版默认 2 个 worker(适合 1GB+ 内存) - 小内存机器可以在 `Dockerfile` 中修改为 1 个 worker: ```dockerfile - CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "1", ...] + CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:7400", "--workers", "1", ...] ``` 4. **文件权限**:确保挂载的目录有适当的读写权限 diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 2420749..1981de4 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -7,7 +7,7 @@ services: dockerfile: Dockerfile.dev container_name: diet_recommendation_app_dev ports: - - "5000:5000" + - "7400:7400" environment: - FLASK_ENV=development - FLASK_DEBUG=1 diff --git a/docker-compose.low-mem.yml b/docker-compose.low-mem.yml index 3989017..68d5bf5 100644 --- a/docker-compose.low-mem.yml +++ b/docker-compose.low-mem.yml @@ -7,7 +7,7 @@ services: dockerfile: Dockerfile.low-mem container_name: diet_recommendation_app_low_mem ports: - - "5000:5000" + - "7400:7400" environment: - FLASK_ENV=production - PYTHONUNBUFFERED=1 @@ -29,7 +29,7 @@ services: networks: - app-network healthcheck: - test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5000/health').read()"] + test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:7400/health').read()"] interval: 30s timeout: 10s retries: 3 diff --git a/docker-compose.yml b/docker-compose.yml index 6423bf9..9234613 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: dockerfile: Dockerfile container_name: diet_recommendation_app ports: - - "5000:5000" + - "7400:7400" environment: - FLASK_ENV=production - PYTHONUNBUFFERED=1 @@ -20,7 +20,7 @@ services: networks: - app-network healthcheck: - test: ["CMD", "python", "-c", "import requests; requests.get('http://localhost:5000/health')"] + test: ["CMD", "python", "-c", "import requests; requests.get('http://localhost:7400/health')"] interval: 30s timeout: 10s retries: 3 diff --git a/start_web.py b/start_web.py index e0b9051..92e14a4 100644 --- a/start_web.py +++ b/start_web.py @@ -33,13 +33,13 @@ def main(): print("\n🚀 正在启动网页服务器...") print("=" * 50) - print("📱 访问地址: http://localhost:5000") - print("📝 背诵排序: http://localhost:5000/recitation") + print("📱 访问地址: http://localhost:7400") + print("📝 背诵排序: http://localhost:7400/recitation") print("\n按 Ctrl+C 停止服务器\n") try: from web_app import app - app.run(debug=True, host='0.0.0.0', port=5000) + app.run(debug=True, host='0.0.0.0', port=7400) except KeyboardInterrupt: print("\n👋 服务器已停止") except Exception as e: diff --git a/web_app.py b/web_app.py index ba66b5a..60bb381 100644 --- a/web_app.py +++ b/web_app.py @@ -697,4 +697,4 @@ if __name__ == '__main__': Path('logs').mkdir(exist_ok=True) # 启动应用 - app.run(debug=True, host='0.0.0.0', port=5000) + app.run(debug=True, host='0.0.0.0', port=7400)