修改端口为7400

This commit is contained in:
2025-11-05 13:32:14 +08:00
parent 3a8a498648
commit d69d0158d8
9 changed files with 28 additions and 28 deletions

View File

@@ -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"]

View File

@@ -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"]

View File

@@ -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"]

View File

@@ -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. **文件权限**:确保挂载的目录有适当的读写权限

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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)