提交docker编译
This commit is contained in:
parent
1a0c5d4e33
commit
ce94f58eb0
|
|
@ -0,0 +1,35 @@
|
|||
# Dockerfile
|
||||
FROM python:3.9-slim
|
||||
|
||||
# 安装nginx
|
||||
RUN apt-get update && apt-get install -y \
|
||||
nginx \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 创建应用目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制后端文件
|
||||
COPY backend/ ./backend/
|
||||
COPY frontend/ /var/www/html/
|
||||
|
||||
# 安装Python依赖
|
||||
RUN pip install --no-cache-dir -r backend/requirements.txt
|
||||
|
||||
# 创建数据和日志目录
|
||||
RUN mkdir -p data logs
|
||||
|
||||
# 配置nginx
|
||||
COPY nginx/nginx.conf /etc/nginx/sites-available/default
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 80
|
||||
|
||||
# 启动脚本
|
||||
COPY sbin/start.sh /start.sh
|
||||
RUN chmod +x /start.sh
|
||||
|
||||
# 初始化数据库
|
||||
RUN python backend/init_db.py
|
||||
|
||||
ENTRYPOINT ["/start.sh"]
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
mvcar:
|
||||
build: .
|
||||
ports:
|
||||
- "80:80"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./logs:/app/logs
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
# 前端静态文件
|
||||
location / {
|
||||
root /var/www/html;
|
||||
index index.html;
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# API请求代理到后端Flask应用
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:5000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
# 健康检查端点
|
||||
location /health {
|
||||
proxy_pass http://127.0.0.1:5000;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,4 +10,32 @@
|
|||
|
||||
## 安装与运行
|
||||
|
||||
1. 安装Python依赖:
|
||||
1. 安装Python依赖:
|
||||
|
||||
|
||||
mvcar/
|
||||
├── backend/
|
||||
│ ├── app.py
|
||||
│ ├── init_db.py
|
||||
│ ├── view_logs.py
|
||||
│ └── requirements.txt
|
||||
├── frontend/
|
||||
│ ├── index.html
|
||||
│ ├── result.html
|
||||
│ ├── css/
|
||||
│ └── js/
|
||||
├── data/
|
||||
├── logs/
|
||||
├── Dockerfile
|
||||
├── nginx.conf
|
||||
├── start.sh
|
||||
└── docker-compose.yml (可选)
|
||||
|
||||
# 构建Docker镜像
|
||||
docker build -t mvcar-app .
|
||||
|
||||
# 运行容器
|
||||
docker run -d -p 80:80 --name mvcar-container mvcar-app
|
||||
|
||||
# 或者使用docker-compose(如果创建了docker-compose.yml)
|
||||
docker-compose up --build -d
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 启动后端Flask应用
|
||||
cd /app/backend
|
||||
nohup python app.py > /app/logs/flask.log 2>&1 &
|
||||
|
||||
# 启动nginx
|
||||
nginx -g "daemon off;"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
@echo off
|
||||
start "" code .
|
||||
Loading…
Reference in New Issue