增加 dockerfile
This commit is contained in:
parent
82281438b0
commit
d3da7fa911
42
.dockerignore
Normal file
42
.dockerignore
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# 依赖目录
|
||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
|
||||||
|
# 构建输出
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
|
||||||
|
# 版本控制
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# 编辑器配置
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
|
|
||||||
|
# 系统文件
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# 日志文件
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# 测试文件
|
||||||
|
coverage
|
||||||
|
test
|
||||||
|
tests
|
||||||
|
|
||||||
|
# 环境变量文件
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
|
||||||
|
# 其他不需要的文件
|
||||||
|
README.md
|
||||||
|
LICENSE
|
||||||
|
docker-compose.yml
|
||||||
32
Dockerfile
Normal file
32
Dockerfile
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# 构建阶段
|
||||||
|
FROM node:18-alpine as build-stage
|
||||||
|
|
||||||
|
# 设置工作目录
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制package.json和package-lock.json
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# 复制项目文件
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 构建项目
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# 生产阶段
|
||||||
|
FROM nginx:stable-alpine as production-stage
|
||||||
|
|
||||||
|
# 复制构建结果到Nginx目录
|
||||||
|
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
|
# 复制自定义Nginx配置(可选)
|
||||||
|
# COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
# 暴露80端口
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# 启动Nginx
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
40
README.md
40
README.md
@ -37,6 +37,39 @@ npm run dev
|
|||||||
npm run build
|
npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Docker部署
|
||||||
|
|
||||||
|
本项目支持使用Docker进行部署,提供了完整的Docker配置。
|
||||||
|
|
||||||
|
### 使用Dockerfile构建镜像
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 构建镜像
|
||||||
|
docker build -t partner-admin:latest .
|
||||||
|
|
||||||
|
# 运行容器
|
||||||
|
docker run -d -p 8080:80 --name partner-admin partner-admin:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用docker-compose部署
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 启动服务
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
docker-compose logs -f
|
||||||
|
|
||||||
|
# 停止服务
|
||||||
|
docker-compose down
|
||||||
|
```
|
||||||
|
|
||||||
|
### 自定义配置
|
||||||
|
|
||||||
|
- 默认将应用部署在80端口,可通过修改`docker-compose.yml`中的端口映射进行调整
|
||||||
|
- Nginx配置文件位于`nginx.conf`,可根据需要修改
|
||||||
|
- 如需添加环境变量,可在`docker-compose.yml`中的environment部分取消注释并添加
|
||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -51,7 +84,12 @@ npm run build
|
|||||||
│ ├── views/ # 页面组件
|
│ ├── views/ # 页面组件
|
||||||
│ ├── App.vue # 根组件
|
│ ├── App.vue # 根组件
|
||||||
│ └── main.js # 入口文件
|
│ └── main.js # 入口文件
|
||||||
├── .babelrc # Babel配置
|
├── .dockerignore # Docker忽略文件
|
||||||
|
├── .gitignore # Git忽略文件
|
||||||
|
├── babel.config.js # Babel配置
|
||||||
|
├── docker-compose.yml # Docker Compose配置
|
||||||
|
├── Dockerfile # Docker构建文件
|
||||||
|
├── nginx.conf # Nginx配置
|
||||||
├── package.json # 项目依赖
|
├── package.json # 项目依赖
|
||||||
├── webpack.config.js # Webpack配置
|
├── webpack.config.js # Webpack配置
|
||||||
└── README.md # 项目说明
|
└── README.md # 项目说明
|
||||||
|
|||||||
23
docker-compose.yml
Normal file
23
docker-compose.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
partner-admin:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: partner-admin
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
# 如果需要环境变量
|
||||||
|
# environment:
|
||||||
|
# - NODE_ENV=production
|
||||||
|
# 如果需要挂载配置文件
|
||||||
|
volumes:
|
||||||
|
- ./nginx.conf:/etc/nginx/conf.d/default.conf
|
||||||
|
networks:
|
||||||
|
- partner-network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
partner-network:
|
||||||
|
driver: bridge
|
||||||
30
nginx.conf
Normal file
30
nginx.conf
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
# 开启gzip
|
||||||
|
gzip on;
|
||||||
|
gzip_min_length 1k;
|
||||||
|
gzip_comp_level 9;
|
||||||
|
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
|
||||||
|
gzip_vary on;
|
||||||
|
|
||||||
|
# 资源文件缓存
|
||||||
|
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
expires 1d;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
# 处理单页应用路由
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 错误页面
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user