diff --git a/Dockerfile.backend b/Dockerfile similarity index 73% rename from Dockerfile.backend rename to Dockerfile index d97b05db..e542f732 100644 --- a/Dockerfile.backend +++ b/Dockerfile @@ -11,13 +11,13 @@ ENV TZ Asia/Shanghai WORKDIR /home # 将当前主机目录全部文件复制至容器工作目录 -COPY ./backend . +COPY backend/requirements.txt . # 安装依赖 -RUN pip install --no-cache-dir -r ./requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple +RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple # 运行应用 CMD ["python", "main.py", "run", "--env=prod"] # 暴露端口 -EXPOSE 8000 +EXPOSE 8001 diff --git a/Dockerfile.frontend b/Dockerfile.frontend deleted file mode 100644 index 41cd418a..00000000 --- a/Dockerfile.frontend +++ /dev/null @@ -1,20 +0,0 @@ -# 使用官方的 Python 3.10 镜像作为基础镜像 -FROM nginx:latest - -# 使用 LABEL 替代 MAINTAINER -LABEL maintainer="948080782@qq.com" - -# 设置时区 -ENV TZ Asia/Shanghai - -# 设置容器内工作目录 -WORKDIR /home - -# 将当前主机目录全部文件复制至容器工作目录 -COPY ./frontend/dist /usr/share/nginx/html - -# 用本地的nginx配置文件覆盖镜像的Nginx配置 -COPY ./nginx.conf /etc/nginx/nginx.conf - -# 暴露端口 -EXPOSE 80 diff --git a/README.en.md b/README.en.md index 0d519be1..c92b61b4 100644 --- a/README.en.md +++ b/README.en.md @@ -225,6 +225,24 @@ git clone https://gitee.com/tao__tao/fastapi_vue3_admin.git - Username: `admin` Password: `123456` - API URL: +### Docker Deployment + +- cd fastapi_vue3_amdin/frontend +- npm run build (Ensure the dist directory exists; otherwise, errors will occur during execution) +- cd fastapi_vue3_amdin +- docker compose up -d +- Notes: +- In the frontend .env.production file, change VITE_API_BASE_URL to the public IP address. +- In the backend .env.prod file, set MYSQL_HOST and REDIS_HOST to private IP addresses. +- Common Issues: +- Backend fails to start: Usually because the initialization script was not executed. The script directory is backend/sql/mysql_xxx.sql. Another possibility is that the MySQL or Redis services are not running and need to be started manually. +- Deployment Order: +- 1. Start MySQL and Redis services +- 2. Execute database initialization scripts. +- 3. Start the backend service. +- 4. Start the frontend service. +- Access URL:Public IP address on port 80; login with username admin and password 123456. + ## 🔧 Module Showcase diff --git a/README.md b/README.md index 5704a3ac..84f40e36 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ fastapi_vue_admin git clone https://gitee.com/tao__tao/fastapi_vue3_admin.git ``` -### 后端 +### 本地后端启动 1. 安装依赖 @@ -177,7 +177,7 @@ git clone https://gitee.com/tao__tao/fastapi_vue3_admin.git # python main.py upgrade --env=dev(不加默认为dev) ``` -### 前端 +### 本地前端启动 1. 安装依赖 @@ -198,7 +198,7 @@ git clone https://gitee.com/tao__tao/fastapi_vue3_admin.git npm run build ``` -### 小程序 +### 本地小程序启动 1. 安装依赖 @@ -219,12 +219,31 @@ git clone https://gitee.com/tao__tao/fastapi_vue3_admin.git npm run build ``` -### 访问项目 +### 本地访问项目 - 前端地址: - 账号:`admin` 密码:`123456` - 接口地址: +### docker 部署 + +- cd fastapi_vue3_amdin/frontend +- npm run build (保证dist前端打包内容存在,否则运行会报错) +- cd fastapi_vue3_amdin +- docker compose up -d +- 注意事项: +- 前端.env.production 中 VITE_API_BASE_URL需要修改为公网地址 +- 后端.env.prod 中 MYSQL_HOST、REDIS_HOST需要改为私网地址 +- 遇到问题: +- 后端启动报错:一般是由于初始化脚本没有执行,脚本目录:backend/sql/mysql_xxx.sql +- 还有可能是因为mysql、redis中间件没有启动,需要手动启动 +- 部署顺序: +- 1. 启动mysql、redis中间件 +- 2. 执行初始化脚本 +- 3. 启动后端服务 +- 4. 启动前端服务 +- 访问地址:公网地址,80端口;登录admin/123456 + ## 🔧 模块展示
diff --git a/backend/dev_sql.db b/backend/dev_sql.db index 2423d6f8..36072a64 100644 Binary files a/backend/dev_sql.db and b/backend/dev_sql.db differ diff --git a/docker-compose.yaml b/docker-compose.yaml index 9af3c8bb..dc5da4d7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -38,14 +38,12 @@ services: # 构建镜像 build: context: . - dockerfile: Dockerfile.backend + dockerfile: Dockerfile # 端口映射 ports: - "8001:8001" volumes: - - /home/backend/static:/home/backend/static - - /home/backend/logs:/home/backend/logs - - /home/backend/env:/home/backend/env + - ./backend:/home - /etc/localtime:/etc/localtime:ro networks: - backend-network @@ -59,14 +57,11 @@ services: container_name: nginx image: "nginx:latest" restart: always - build: - context: . - dockerfile: Dockerfile.frontend ports: - "80:80" volumes: - - /home/frontend/nginx/conf:/etc/nginx/conf - - /home/frontend/nginx/dist:/usr/share/nginx/html + - ./nginx.conf:/etc/nginx/nginx.conf + - ./frontend/dist:/usr/share/nginx/html networks: - frontend_network depends_on: @@ -76,16 +71,12 @@ services: networks: mysql_network: driver: bridge - name: mysql_network redis_network: driver: bridge - name: redis_network frontend_network: driver: bridge - name: frontend_network backend-network: driver: bridge - name: backend-network # 文件挂载 volumes: diff --git a/frontend/.env.production b/frontend/.env.production index 5bc4663d..b7844521 100644 --- a/frontend/.env.production +++ b/frontend/.env.production @@ -9,7 +9,7 @@ VITE_APP_TITLE=生产环境 VITE_APP_BASE_API=/api/v1 # 网络请求公用地址 -VITE_API_BASE_URL='https://fastapi-vue-admin.cn' +VITE_API_BASE_URL='http://8.137.99.5:8001' # 请求超时时间 VITE_TIMEOUT=10000 \ No newline at end of file diff --git a/frontend/public/site/404.html b/frontend/public/site/404.html index ea83eb5e..da214c41 100644 --- a/frontend/public/site/404.html +++ b/frontend/public/site/404.html @@ -214,24 +214,6 @@ -
  • - - - - 部署指南 - - -
  • - - - - - - - - - -
  • @@ -430,7 +412,7 @@ - 部署指南 + 文档指南 @@ -440,74 +422,6 @@ - -
  • - - - - - - - - - - - - - - - - -
  • - - - - - - - - -