docker compose首次启动加载sql脚本

This commit is contained in:
dhb52 2023-07-28 17:08:29 +08:00
parent 7f657ee931
commit 0fb3c4bfcc
2 changed files with 21 additions and 41 deletions

View File

@ -1,6 +1,7 @@
# Docker Build & Up # Docker Build & Up
目标: 快速部署体验系统,帮助了解系统之间的依赖关系。 目标: 快速部署体验系统,帮助了解系统之间的依赖关系。
依赖docker compose v2删除`name: yudao-system`,降低`version`版本为`3.3`以下,支持`docker-compose`。
## 功能文件列表 ## 功能文件列表
@ -8,16 +9,16 @@
. .
├── Docker-HOWTO.md ├── Docker-HOWTO.md
├── docker-compose.yml ├── docker-compose.yml
├── docker.env ├── docker.env <-- 提供docker-compose环境变量配置
├── yudao-server ├── yudao-server
│ ├── Dockerfile │ └── Dockerfile
│ └── nginx.conf
└── yudao-ui-admin └── yudao-ui-admin
├── .dockerignore ├── .dockerignore
└── Dockerfile ├── Dockerfile
└── nginx.conf <-- 提供基础配置gzip压缩api转发
``` ```
## Maven build (Optional) ## 构建 jar 包
```shell ```shell
# 创建maven缓存volume # 创建maven缓存volume
@ -30,29 +31,19 @@ docker run -it --rm --name yudao-maven \
maven mvn clean install package '-Dmaven.test.skip=true' maven mvn clean install package '-Dmaven.test.skip=true'
``` ```
## Docker Compose Build ## 构建启动服务
```shell
docker compose --env-file docker.env build
```
## Docker Compose Up
```shell ```shell
docker compose --env-file docker.env up -d docker compose --env-file docker.env up -d
``` ```
第一次执行由于数据库未初始化因此yudao-server容器会运行失败。执行如下命令初始化数据库 首次运行会自动构建容器。可以通过`docker compose build [service]`来手动构建所有或某个docker镜像
```shell `--env-file docker.env`为可选参数,只是展示了通过`.env`文件配置容器启动的环境变量,`docker-compose.yml`本身已经提供足够的默认参数来正常运行系统。
docker compose exec -T mysql \
sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" --default-character-set=utf8mb4 ruoyi-vue-pro' \
< ./sql/mysql/ruoyi-vue-pro.sql
```
## Server:Port ## 服务器的宿主机端口映射
- admin: http://localhost:8080 - admin ui: http://localhost:8080
- API: http://localhost:48080 - api server: http://localhost:48080
- mysql: root/123456, port: 3308 - mysql: root/123456, port: 3306
- redis: port: 6379 - redis: port: 6379

View File

@ -1,4 +1,4 @@
version: "3.8" version: "3.4"
name: yudao-system name: yudao-system
@ -9,25 +9,22 @@ services:
restart: unless-stopped restart: unless-stopped
tty: true tty: true
ports: ports:
- 13306:3306 - "3306:3306"
environment: environment:
MYSQL_DATABASE: ${MYSQL_DATABASE:-ruoyi-vue-pro} MYSQL_DATABASE: ${MYSQL_DATABASE:-ruoyi-vue-pro}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-123456} MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-123456}
volumes: volumes:
- mysql:/var/lib/mysql/ - mysql:/var/lib/mysql/
networks: - ./sql/mysql/ruoyi-vue-pro.sql:/docker-entrypoint-initdb.d/ruoyi-vue-pro.sql:ro
- yudao-network
redis: redis:
container_name: yudao-redis container_name: yudao-redis
image: redis:6-alpine image: redis:6-alpine
restart: unless-stopped restart: unless-stopped
ports: ports:
- 16379:6379 - "6379:6379"
volumes: volumes:
- redis:/data - redis:/data
networks:
- yudao-network
server: server:
container_name: yudao-server container_name: yudao-server
@ -36,7 +33,7 @@ services:
image: yudao-server image: yudao-server
restart: unless-stopped restart: unless-stopped
ports: ports:
- 48080:48080 - "48080:48080"
environment: environment:
# https://github.com/polovyivan/docker-pass-configs-to-container # https://github.com/polovyivan/docker-pass-configs-to-container
SPRING_PROFILES_ACTIVE: local SPRING_PROFILES_ACTIVE: local
@ -54,8 +51,6 @@ services:
--spring.datasource.dynamic.datasource.slave.username=${SLAVE_DATASOURCE_USERNAME:-root} --spring.datasource.dynamic.datasource.slave.username=${SLAVE_DATASOURCE_USERNAME:-root}
--spring.datasource.dynamic.datasource.slave.password=${SLAVE_DATASOURCE_PASSWORD:-123456} --spring.datasource.dynamic.datasource.slave.password=${SLAVE_DATASOURCE_PASSWORD:-123456}
--spring.redis.host=${REDIS_HOST:-yudao-redis} --spring.redis.host=${REDIS_HOST:-yudao-redis}
networks:
- yudao-network
depends_on: depends_on:
- mysql - mysql
- redis - redis
@ -78,16 +73,10 @@ services:
image: yudao-admin image: yudao-admin
restart: unless-stopped restart: unless-stopped
ports: ports:
- 8080:80 - "8080:80"
networks:
- yudao-network
depends_on: depends_on:
- server - server
networks:
yudao-network:
driver: bridge
volumes: volumes:
mysql: mysql:
driver: local driver: local