修改端口为7400
This commit is contained in:
@@ -42,14 +42,14 @@ RUN mkdir -p templates static/css static/js logs data models
|
|||||||
RUN chmod +x start_web.py
|
RUN chmod +x start_web.py
|
||||||
|
|
||||||
# 暴露端口
|
# 暴露端口
|
||||||
EXPOSE 5000
|
EXPOSE 7400
|
||||||
|
|
||||||
# 健康检查
|
# 健康检查
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
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启动应用(生产环境)
|
# 使用gunicorn启动应用(生产环境)
|
||||||
# 注意:默认配置使用2个worker,适合1GB+内存的机器
|
# 注意:默认配置使用2个worker,适合1GB+内存的机器
|
||||||
# 如果机器内存较小(512MB-1GB),建议修改为 "--workers", "1"
|
# 如果机器内存较小(512MB-1GB),建议修改为 "--workers", "1"
|
||||||
# 使用 python -m gunicorn 确保可以找到 gunicorn(即使可执行文件不在PATH中也能工作)
|
# 使用 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"]
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ COPY . .
|
|||||||
RUN mkdir -p templates static/css static/js logs data models
|
RUN mkdir -p templates static/css static/js logs data models
|
||||||
|
|
||||||
# 暴露端口
|
# 暴露端口
|
||||||
EXPOSE 5000
|
EXPOSE 7400
|
||||||
|
|
||||||
# 开发模式:使用Flask开发服务器
|
# 开发模式:使用Flask开发服务器
|
||||||
CMD ["python", "start_web.py"]
|
CMD ["python", "start_web.py"]
|
||||||
|
|||||||
@@ -56,13 +56,13 @@ RUN mkdir -p templates static/css static/js logs data models
|
|||||||
RUN chmod +x start_web.py
|
RUN chmod +x start_web.py
|
||||||
|
|
||||||
# 暴露端口
|
# 暴露端口
|
||||||
EXPOSE 5000
|
EXPOSE 7400
|
||||||
|
|
||||||
# 健康检查(不使用 requests,直接用 Python)
|
# 健康检查(不使用 requests,直接用 Python)
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
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,减少内存占用)
|
# 使用gunicorn启动应用(小内存配置:单worker,减少内存占用)
|
||||||
# 使用 python -m gunicorn 确保可以找到 gunicorn(即使可执行文件不在PATH中也能工作)
|
# 使用 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"]
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ docker build -t diet-recommendation-app .
|
|||||||
# 运行容器
|
# 运行容器
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name diet_recommendation_app \
|
--name diet_recommendation_app \
|
||||||
-p 5000:5000 \
|
-p 7400:7400 \
|
||||||
-v $(pwd)/data:/app/data \
|
-v $(pwd)/data:/app/data \
|
||||||
-v $(pwd)/logs:/app/logs \
|
-v $(pwd)/logs:/app/logs \
|
||||||
-v $(pwd)/models:/app/models \
|
-v $(pwd)/models:/app/models \
|
||||||
@@ -63,12 +63,12 @@ docker rm diet_recommendation_app
|
|||||||
## 🌐 访问应用
|
## 🌐 访问应用
|
||||||
|
|
||||||
容器启动后,访问:
|
容器启动后,访问:
|
||||||
- **主页**: http://localhost:5000
|
- **主页**: http://localhost:7400
|
||||||
- **背诵排序**: http://localhost:5000/recitation
|
- **背诵排序**: http://localhost:7400/recitation
|
||||||
- **数据采集**: http://localhost:5000/data-collection
|
- **数据采集**: http://localhost:7400/data-collection
|
||||||
- **智能推荐**: http://localhost:5000/recommendation
|
- **智能推荐**: http://localhost:7400/recommendation
|
||||||
- **营养分析**: http://localhost:5000/analysis
|
- **营养分析**: http://localhost:7400/analysis
|
||||||
- **健康检查**: http://localhost:5000/health
|
- **健康检查**: http://localhost:7400/health
|
||||||
|
|
||||||
## 📁 数据持久化
|
## 📁 数据持久化
|
||||||
|
|
||||||
@@ -92,11 +92,11 @@ environment:
|
|||||||
|
|
||||||
### 端口配置
|
### 端口配置
|
||||||
|
|
||||||
默认端口为 `5000`,如需修改:
|
默认端口为 `7400`,如需修改:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
ports:
|
ports:
|
||||||
- "8080:5000" # 将主机的8080端口映射到容器的5000端口
|
- "8080:7400" # 将主机的8080端口映射到容器的7400端口
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🐛 故障排除
|
## 🐛 故障排除
|
||||||
@@ -153,7 +153,7 @@ docker-compose ps
|
|||||||
docker ps
|
docker ps
|
||||||
```
|
```
|
||||||
|
|
||||||
健康检查端点:`http://localhost:5000/health`
|
健康检查端点:`http://localhost:7400/health`
|
||||||
|
|
||||||
## 🔒 安全建议
|
## 🔒 安全建议
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ server {
|
|||||||
server_name your-domain.com;
|
server_name your-domain.com;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://localhost:5000;
|
proxy_pass http://localhost:7400;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
@@ -246,7 +246,7 @@ services:
|
|||||||
- 标准版默认 2 个 worker(适合 1GB+ 内存)
|
- 标准版默认 2 个 worker(适合 1GB+ 内存)
|
||||||
- 小内存机器可以在 `Dockerfile` 中修改为 1 个 worker:
|
- 小内存机器可以在 `Dockerfile` 中修改为 1 个 worker:
|
||||||
```dockerfile
|
```dockerfile
|
||||||
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "1", ...]
|
CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:7400", "--workers", "1", ...]
|
||||||
```
|
```
|
||||||
|
|
||||||
4. **文件权限**:确保挂载的目录有适当的读写权限
|
4. **文件权限**:确保挂载的目录有适当的读写权限
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ services:
|
|||||||
dockerfile: Dockerfile.dev
|
dockerfile: Dockerfile.dev
|
||||||
container_name: diet_recommendation_app_dev
|
container_name: diet_recommendation_app_dev
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "7400:7400"
|
||||||
environment:
|
environment:
|
||||||
- FLASK_ENV=development
|
- FLASK_ENV=development
|
||||||
- FLASK_DEBUG=1
|
- FLASK_DEBUG=1
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ services:
|
|||||||
dockerfile: Dockerfile.low-mem
|
dockerfile: Dockerfile.low-mem
|
||||||
container_name: diet_recommendation_app_low_mem
|
container_name: diet_recommendation_app_low_mem
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "7400:7400"
|
||||||
environment:
|
environment:
|
||||||
- FLASK_ENV=production
|
- FLASK_ENV=production
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
@@ -29,7 +29,7 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
healthcheck:
|
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
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ services:
|
|||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: diet_recommendation_app
|
container_name: diet_recommendation_app
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "7400:7400"
|
||||||
environment:
|
environment:
|
||||||
- FLASK_ENV=production
|
- FLASK_ENV=production
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
@@ -20,7 +20,7 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
healthcheck:
|
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
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ def main():
|
|||||||
|
|
||||||
print("\n🚀 正在启动网页服务器...")
|
print("\n🚀 正在启动网页服务器...")
|
||||||
print("=" * 50)
|
print("=" * 50)
|
||||||
print("📱 访问地址: http://localhost:5000")
|
print("📱 访问地址: http://localhost:7400")
|
||||||
print("📝 背诵排序: http://localhost:5000/recitation")
|
print("📝 背诵排序: http://localhost:7400/recitation")
|
||||||
print("\n按 Ctrl+C 停止服务器\n")
|
print("\n按 Ctrl+C 停止服务器\n")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from web_app import app
|
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:
|
except KeyboardInterrupt:
|
||||||
print("\n👋 服务器已停止")
|
print("\n👋 服务器已停止")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -697,4 +697,4 @@ if __name__ == '__main__':
|
|||||||
Path('logs').mkdir(exist_ok=True)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user