提交docker编译
This commit is contained in:
parent
ce94f58eb0
commit
e4e52db4f3
|
|
@ -1,11 +1,27 @@
|
|||
# Dockerfile
|
||||
FROM python:3.9-slim
|
||||
|
||||
# 安装nginx
|
||||
RUN apt-get update && apt-get install -y \
|
||||
# 设置时区
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
# 完全清空并重写所有源文件
|
||||
RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/* && \
|
||||
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main" > /etc/apt/sources.list && \
|
||||
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main" >> /etc/apt/sources.list && \
|
||||
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security trixie-security main" >> /etc/apt/sources.list
|
||||
|
||||
|
||||
# 设置 ll 别名
|
||||
RUN echo "alias ll='ls -alF'" >> /root/.bashrc
|
||||
|
||||
# 安装 nginx
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
nginx \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 设置 pip 清华源
|
||||
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
|
||||
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn
|
||||
|
||||
# 创建应用目录
|
||||
WORKDIR /app
|
||||
|
||||
|
|
@ -32,4 +48,4 @@ RUN chmod +x /start.sh
|
|||
# 初始化数据库
|
||||
RUN python backend/init_db.py
|
||||
|
||||
ENTRYPOINT ["/start.sh"]
|
||||
ENTRYPOINT ["/start.sh"]
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ CORS(app)
|
|||
def get_db_connection():
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
# 确保使用UTF-8编码
|
||||
conn.execute('PRAGMA encoding = "UTF-8"')
|
||||
return conn
|
||||
|
||||
@app.route('/api/cars', methods=['GET'])
|
||||
|
|
@ -69,6 +71,7 @@ def search_car():
|
|||
|
||||
try:
|
||||
conn = get_db_connection()
|
||||
# 修改查询语句以正确处理中文字符
|
||||
cars = conn.execute('SELECT * FROM cars WHERE plate LIKE ?', (f'%{plate}%',)).fetchall()
|
||||
conn.close()
|
||||
|
||||
|
|
@ -85,6 +88,7 @@ def get_car_by_plate(plate):
|
|||
|
||||
try:
|
||||
conn = get_db_connection()
|
||||
# 修改查询语句以正确处理中文字符
|
||||
car = conn.execute('SELECT * FROM cars WHERE plate = ?', (plate,)).fetchone()
|
||||
conn.close()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# backend/init_db.py
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
|
|
@ -10,6 +11,8 @@ os.makedirs(os.path.dirname(db_path), exist_ok=True)
|
|||
|
||||
# 创建数据库连接
|
||||
conn = sqlite3.connect(db_path)
|
||||
# 确保使用UTF-8编码
|
||||
conn.execute('PRAGMA encoding = "UTF-8"')
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 创建车辆表
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
}
|
||||
|
||||
// 从后端API获取数据
|
||||
console.log(`发送请求到: http://localhost:5000/api/cars/search?plate=${encodeURIComponent(plate)}`);
|
||||
fetch(`http://localhost:5000/api/cars/search?plate=${encodeURIComponent(plate)}`)
|
||||
console.log(`发送请求到: /api/cars/search?plate=${encodeURIComponent(plate)}`);
|
||||
fetch(`/api/cars/search?plate=${encodeURIComponent(plate)}`)
|
||||
.then(response => {
|
||||
console.log(`收到响应状态: ${response.status}`);
|
||||
if (!response.ok) {
|
||||
|
|
|
|||
|
|
@ -34,8 +34,11 @@ mvcar/
|
|||
# 构建Docker镜像
|
||||
docker build -t mvcar-app .
|
||||
|
||||
# 构建Docker镜像
|
||||
docker build -t mvcar-app:v1.0.0 -t mvcar-app:latest .
|
||||
|
||||
# 运行容器
|
||||
docker run -d -p 80:80 --name mvcar-container mvcar-app
|
||||
|
||||
# 或者使用docker-compose(如果创建了docker-compose.yml)
|
||||
docker-compose up --build -d
|
||||
docker-compose up --build -d
|
||||
|
|
|
|||
Loading…
Reference in New Issue