若依官方文档–> https://doc.ruoyi.vip/ruoyi-cloud/document/hjbs.html#%E9%83%A8%E7%BD%B2%E7%B3%BB%E7%BB%9F
1.相关jar包准备
mvn clean
mvn package
打最新的jar包到target目录下
若依后台打包
将本地开发测试数据库的数据导出成sql脚本,放入sql这个文件夹
编写docker下copy.sh文件
执行脚本,相应文件已经拷贝到docker目录下
2.修改相关配置文件
2.1 mysql
1 2 3 4 5 6 7
| FROM mysql:5.7
MAINTAINER ruoyi
ADD ./db/*.sql /docker-entrypoint-initdb.d/
|
在使用 mysql:5.7 作为基础镜像时,MySQL 官方镜像提供了一个特性,即在容器启动时会自动执行 /docker-entrypoint-initdb.d/ 目录下的所有 .sql 文件。也就是说,当启动基于这个镜像的容器时,MySQL 会自动运行这些 SQL 脚本来初始化数据库。
2.2 nacos
1 2 3 4 5 6 7
| FROM nacos/nacos-server
MAINTAINER ruoyi
COPY ./conf/application.properties /home/nacos/conf/application.properties
|
2.3 nginx
nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| worker_processes 1;
events { worker_connections 1024; }
http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65;
server { listen 80; server_name localhost;
location / { root /home/ruoyi/projects/ruoyi-ui; try_files $uri $uri/ /index.html; index index.html index.htm; }
location /prod-api/{ 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; proxy_pass http://ruoyi-gateway:8080/; }
# 避免actuator暴露 if ($request_uri ~ "/actuator") { return 403; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
|
将所有发往 /prod-api/ 的请求代理转发到 ruoyi-gateway 服务器,同时保留和传递原始请求的相关头信息
2.4 redis
1 2 3 4 5 6 7 8 9 10 11 12 13
| FROM redis
MAINTAINER ruoyi
VOLUME /home/ruoyi/redis
RUN mkdir -p /home/ruoyi/redis
WORKDIR /home/ruoyi/redis
COPY ./conf/redis.conf /home/ruoyi/redis/redis.conf
|
2.5 ruoyi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| FROM docker.m.daocloud.io/library/eclipse-temurin:17-jre
MAINTAINER ruoyi
ENV JAR_FILE=ruoyi-modules-midjourney-proxy-3.6.3.jar
VOLUME /home/ruoyi
RUN mkdir -p /home/ruoyi
WORKDIR /home/ruoyi
COPY ./jar/${JAR_FILE} /home/ruoyi/${JAR_FILE}
ENTRYPOINT ["java","-jar","${JAR_FILE}"]
|
ruoyi文件下的其他dockerfile书写类似
2.6 docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| version : '3.8' services: ruoyi-nacos: container_name: ruoyi-nacos image: nacos/nacos-server build: context: ./nacos environment: - MODE=standalone volumes: - ./nacos/logs/:/home/nacos/logs - ./nacos/conf/application.properties:/home/nacos/conf/application.properties ports: - "8850:8848" depends_on: - ruoyi-mysql ruoyi-mysql: container_name: ruoyi-mysql image: mysql:5.7 build: context: ./mysql ports: - "3307:3306" volumes: - ./mysql/conf:/etc/mysql/conf.d - ./mysql/logs:/logs - ./mysql/data:/var/lib/mysql command: [ 'mysqld', '--innodb-buffer-pool-size=80M', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--default-time-zone=+8:00', '--lower-case-table-names=1' ] environment: MYSQL_DATABASE: 'ry-cloud' MYSQL_ROOT_PASSWORD: password ruoyi-redis: container_name: ruoyi-redis image: redis build: context: ./redis ports: - "6380:6379" volumes: - ./redis/conf/redis.conf:/home/ruoyi/redis/redis.conf - ./redis/data:/data command: redis-server /home/ruoyi/redis/redis.conf ruoyi-nginx: container_name: ruoyi-nginx image: nginx build: context: ./nginx ports: - "81:80" volumes: - ./nginx/html/dist:/home/ruoyi/projects/ruoyi-ui - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf - ./nginx/logs:/var/log/nginx - ./nginx/conf.d:/etc/nginx/conf.d depends_on: - ruoyi-gateway links: - ruoyi-gateway ruoyi-gateway: container_name: ruoyi-gateway build: context: ./ruoyi/gateway dockerfile: dockerfile ports: - "8081:8080" depends_on: - ruoyi-redis links: - ruoyi-redis ruoyi-auth: container_name: ruoyi-auth build: context: ./ruoyi/auth dockerfile: dockerfile ports: - "9210:9200" depends_on: - ruoyi-redis links: - ruoyi-redis ruoyi-modules-system: container_name: ruoyi-modules-system build: context: ./ruoyi/modules/system dockerfile: dockerfile ports: - "9201:9201" depends_on: - ruoyi-redis - ruoyi-mysql links: - ruoyi-redis - ruoyi-mysql ruoyi-modules-midjourney-proxy: container_name: ruoyi-modules-midjourney-proxy build: context: ./ruoyi/modules/midjourney dockerfile: dockerfile ports: - "10086:10086" depends_on: - ruoyi-redis - ruoyi-mysql links: - ruoyi-redis - ruoyi-mysql
|
配置容器名称,构建方法,端口,依赖管理
3.运行部署
在开始之前,请确保你的系统上已经安装了 Docker 和 Docker Compose。如果还没有安装,可以根据你的操作系统类型进行安装。
• Docker 安装:Docker 官方安装指南
• Docker Compose 安装:Docker Compose 安装指南
使用 cd 命令导航到包含 docker-compose.yml 文件的目录
运行以下命令启动 docker-compose.yml 文件中定义的所有服务:
如果你希望在后台运行这些服务(即以“守护进程”模式运行),可以使用 -d 选项
直接将整个docker文件夹上传,然后运行
有时候nacos的构建会报错,因为mysql没有初始化完成,nacos就开始读ry-config表
最后再测试即可