commit
dbdf1d9fb0
60
Docker-HOWTO.md
Normal file
60
Docker-HOWTO.md
Normal file
@ -0,0 +1,60 @@
|
||||
# Docker Build & Up
|
||||
|
||||
目标: 快速部署体验系统,帮助了解系统之间的依赖关系。
|
||||
|
||||
## 功能文件列表
|
||||
|
||||
```text
|
||||
.
|
||||
├── Docker-HOWTO.md
|
||||
├── docker-compose.yml
|
||||
├── docker.env
|
||||
├── yudao-server
|
||||
│ ├── Dockerfile
|
||||
│ └── nginx.conf
|
||||
└── yudao-ui-admin
|
||||
├── .dockerignore
|
||||
└── Dockerfile
|
||||
```
|
||||
|
||||
## Maven build (Optional)
|
||||
|
||||
```shell
|
||||
# 创建maven缓存volume
|
||||
docker volume create --name yudao-maven-repo
|
||||
|
||||
docker run -it --rm --name yudao-maven \
|
||||
-v yudao-maven-repo:/root/.m2 \
|
||||
-v $PWD:/usr/src/mymaven \
|
||||
-w /usr/src/mymaven \
|
||||
maven mvn clean install package '-Dmaven.test.skip=true'
|
||||
```
|
||||
|
||||
## Docker Compose Build
|
||||
|
||||
```shell
|
||||
docker compose --env-file docker.env build
|
||||
```
|
||||
|
||||
## Docker Compose Up
|
||||
|
||||
```shell
|
||||
docker compose --env-file docker.env up -d
|
||||
```
|
||||
|
||||
第一次执行,由于数据库未初始化,因此yudao-server容器会运行失败。执行如下命令初始化数据库:
|
||||
|
||||
```shell
|
||||
docker exec -i yudao-mysql \
|
||||
sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" ruoyi-vue-pro' \
|
||||
< ./sql/mysql/ruoyi-vue-pro.sql
|
||||
```
|
||||
|
||||
注意:这里用docker compose exec 会出现 `the input device is not a TTY` 报错
|
||||
|
||||
## Server:Port
|
||||
|
||||
- admin: http://localhost:8080
|
||||
- API: http://localhost:48080
|
||||
- mysql: root/123456, port: 3308
|
||||
- redis: port: 6379
|
95
docker-compose.yml
Normal file
95
docker-compose.yml
Normal file
@ -0,0 +1,95 @@
|
||||
version: "3.8"
|
||||
|
||||
name: yudao-system
|
||||
|
||||
services:
|
||||
mysql:
|
||||
container_name: yudao-mysql
|
||||
image: mysql:8
|
||||
restart: unless-stopped
|
||||
tty: true
|
||||
ports:
|
||||
- 13306:3306
|
||||
environment:
|
||||
MYSQL_DATABASE: ${MYSQL_DATABASE:-ruoyi-vue-pro}
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-123456}
|
||||
volumes:
|
||||
- mysql:/var/lib/mysql/
|
||||
networks:
|
||||
- yudao-network
|
||||
|
||||
redis:
|
||||
container_name: yudao-redis
|
||||
image: redis:6-alpine
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 16379:6379
|
||||
volumes:
|
||||
- redis:/data
|
||||
networks:
|
||||
- yudao-network
|
||||
|
||||
server:
|
||||
container_name: yudao-server
|
||||
build:
|
||||
context: ./yudao-server/
|
||||
image: yudao-server
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 48080:48080
|
||||
environment:
|
||||
# https://github.com/polovyivan/docker-pass-configs-to-container
|
||||
SPRING_PROFILES_ACTIVE: local
|
||||
JAVA_OPTS:
|
||||
${JAVA_OPTS:-
|
||||
-Xms512m
|
||||
-Xmx512m
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
}
|
||||
ARGS:
|
||||
--spring.datasource.dynamic.datasource.master.url=${MASTER_DATASOURCE_URL:-jdbc:mysql://yudao-mysql:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true}
|
||||
--spring.datasource.dynamic.datasource.master.username=${MASTER_DATASOURCE_USERNAME:-root}
|
||||
--spring.datasource.dynamic.datasource.master.password=${MASTER_DATASOURCE_PASSWORD:-123456}
|
||||
--spring.datasource.dynamic.datasource.slave.url=${SLAVE_DATASOURCE_URL:-jdbc:mysql://yudao-mysql:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true}
|
||||
--spring.datasource.dynamic.datasource.slave.username=${SLAVE_DATASOURCE_USERNAME:-root}
|
||||
--spring.datasource.dynamic.datasource.slave.password=${SLAVE_DATASOURCE_PASSWORD:-123456}
|
||||
--spring.redis.host=${REDIS_HOST:-yudao-redis}
|
||||
networks:
|
||||
- yudao-network
|
||||
depends_on:
|
||||
- mysql
|
||||
- redis
|
||||
|
||||
admin:
|
||||
container_name: yudao-admin
|
||||
build:
|
||||
context: ./yudao-ui-admin
|
||||
args:
|
||||
NODE_ENV:
|
||||
ENV=${NODE_ENV:-production}
|
||||
PUBLIC_PATH=${PUBLIC_PATH:-/}
|
||||
VUE_APP_TITLE=${VUE_APP_TITLE:-芋道管理系统}
|
||||
VUE_APP_BASE_API=${VUE_APP_BASE_API:-/prod-api}
|
||||
VUE_APP_APP_NAME=${VUE_APP_APP_NAME:-/}
|
||||
VUE_APP_TENANT_ENABLE=${VUE_APP_TENANT_ENABLE:-true}
|
||||
VUE_APP_CAPTCHA_ENABLE=${VUE_APP_CAPTCHA_ENABLE:-true}
|
||||
VUE_APP_DOC_ENABLE=${VUE_APP_DOC_ENABLE:-true}
|
||||
VUE_APP_BAIDU_CODE=${VUE_APP_BAIDU_CODE:-fadc1bd5db1a1d6f581df60a1807f8ab}
|
||||
image: yudao-admin
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8080:80
|
||||
networks:
|
||||
- yudao-network
|
||||
depends_on:
|
||||
- server
|
||||
|
||||
networks:
|
||||
yudao-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
mysql:
|
||||
driver: local
|
||||
redis:
|
||||
driver: local
|
25
docker.env
Normal file
25
docker.env
Normal file
@ -0,0 +1,25 @@
|
||||
## mysql
|
||||
MYSQL_DATABASE=ruoyi-vue-pro
|
||||
MYSQL_ROOT_PASSWORD=123456
|
||||
|
||||
## server
|
||||
JAVA_OPTS=-Xms512m -Xmx512m -Djava.security.egd=file:/dev/./urandom
|
||||
|
||||
MASTER_DATASOURCE_URL=jdbc:mysql://yudao-mysql:3306/${MYSQL_DATABASE}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||
MASTER_DATASOURCE_USERNAME=root
|
||||
MASTER_DATASOURCE_PASSWORD=${MYSQL_ROOT_PASSWORD}
|
||||
SLAVE_DATASOURCE_URL=${MASTER_DATASOURCE_URL}
|
||||
SLAVE_DATASOURCE_USERNAME=${MASTER_DATASOURCE_USERNAME}
|
||||
SLAVE_DATASOURCE_PASSWORD=${MASTER_DATASOURCE_PASSWORD}
|
||||
REDIS_HOST=yudao-redis
|
||||
|
||||
## admin
|
||||
NODE_ENV=production
|
||||
PUBLIC_PATH=/
|
||||
VUE_APP_TITLE=芋道管理系统
|
||||
VUE_APP_BASE_API=/prod-api
|
||||
VUE_APP_APP_NAME=/
|
||||
VUE_APP_TENANT_ENABLE=true
|
||||
VUE_APP_CAPTCHA_ENABLE=true
|
||||
VUE_APP_DOC_ENABLE=true
|
||||
VUE_APP_BAIDU_CODE=fadc1bd5db1a1d6f581df60a1807f8ab
|
@ -9,11 +9,15 @@ WORKDIR /yudao-server
|
||||
COPY ./target/yudao-server.jar app.jar
|
||||
|
||||
## 设置 TZ 时区
|
||||
ENV TZ=Asia/Shanghai
|
||||
## 设置 JAVA_OPTS 环境变量,可通过 docker run -e "JAVA_OPTS=" 进行覆盖
|
||||
ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms512m -Xmx512m"
|
||||
ENV JAVA_OPTS="-Xms512m -Xmx512m -Djava.security.egd=file:/dev/./urandom"
|
||||
|
||||
## 应用参数
|
||||
ENV ARGS=""
|
||||
|
||||
## 暴露后端项目的 48080 端口
|
||||
EXPOSE 48080
|
||||
|
||||
## 启动后端项目
|
||||
CMD java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar app.jar
|
||||
CMD java ${JAVA_OPTS} -jar app.jar $ARGS
|
||||
|
3
yudao-ui-admin/.dockerignore
Normal file
3
yudao-ui-admin/.dockerignore
Normal file
@ -0,0 +1,3 @@
|
||||
.dockerignore
|
||||
dist
|
||||
node_modules
|
21
yudao-ui-admin/Dockerfile
Normal file
21
yudao-ui-admin/Dockerfile
Normal file
@ -0,0 +1,21 @@
|
||||
FROM node:16-alpine as build-stage
|
||||
|
||||
WORKDIR /admim
|
||||
|
||||
COPY .npmrc package.json yarn.lock ./
|
||||
RUN --mount=type=cache,id=yarn-store,target=/root/.yarn-store \
|
||||
yarn install --frozen-lockfile
|
||||
|
||||
COPY . .
|
||||
ARG NODE_ENV=""
|
||||
RUN env ${NODE_ENV} yarn build:prod
|
||||
|
||||
## -- stage: dist => nginx --
|
||||
FROM nginx:alpine
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=build-stage /admim/dist /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
26
yudao-ui-admin/nginx.conf
Normal file
26
yudao-ui-admin/nginx.conf
Normal file
@ -0,0 +1,26 @@
|
||||
server {
|
||||
listen 80 default_server;
|
||||
server_name _; ## 重要!!!修改成你的外网 IP/域名
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1k; # 设置允许压缩的页面最小字节数
|
||||
gzip_buffers 4 16k; # 用来存储 gzip 的压缩结果
|
||||
gzip_http_version 1.1; # 识别 HTTP 协议版本
|
||||
gzip_comp_level 2; # 设置 gzip 的压缩比 1-9。1 压缩比最小但最快,而 9 相反
|
||||
gzip_types text/plain application/x-javascript text/css application/xml application/javascript; # 指定压缩类型
|
||||
gzip_proxied any; # 无论后端服务器的 headers 头返回什么信息,都无条件启用压缩
|
||||
|
||||
location / { ## 前端项目
|
||||
root /usr/share/nginx/html/;
|
||||
index index.html index.htm;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /prod-api/ { ## 后端项目 - 管理后台
|
||||
proxy_pass http://yudao-server:48080/; ## 重要!!!proxy_pass 需要设置为后端项目所在服务器的 IP
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header REMOTE-HOST $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user