Deploy rouyi-cloud using docker-compose

Foreword

For learning and practice only.
If deployed according to system docker-compose
The following commands are applicable to CentOS7.x version, and my experimental environment is a virtual machine.

1. Install docker

Not to go into details

2. Install docker-compose

Not to go into details

3. Ruoyi deployment

  1. Get Ruoyi deployment files

    Obtain address: https://gitee.com/y_project/RuoYi-Cloud/tree/master/docker

    The directory structure is as follows:

    ├── docker
    │ ├── copy.sh
    │ ├── deploy.sh
    │ ├── docker-compose.yml
    │ ├── mysql
    │ │ ├── conf
    │ │ ├── data
    │ │ ├── db
    │ │ ├── dockerfile
    │ │ └── logs
    │ ├── nacos
    │ │ ├── conf
    │ │ ├── dockerfile
    │ │ └── logs
    │ ├── nginx
    │ │ ├── conf
    │ │ ├── conf.d
    │ │ ├── dockerfile
    │ │ ├── html
    │ │ └── logs
    │ ├── redis
    │ │ ├── conf
    │ │ ├── data
    │ │ └── dockerfile
    │ └── ruoyi
    │ ├── auth
    │ ├── gateway
    │ ├── modules
    │ └── visual
    
  2. Download dependency images

    The dependent image name can be obtained from the docker/docker-compose.yaml file:

    [root@localhost docker]# cat docker-compose.yml | grep image:
        image: nacos/nacos-server
        image: mysql:5.7
        image: redis
        image: nginx
    

    Download the image and execute the command:

    docker pull nacos/nacos-server
    docker pull mysql:5.7
    docker pull redis
    docker pull nginx
    
  3. Start Ruoyi basic service

    Script authorization:

    cd docker
    chmod +x deploy.sh
    

    Start basic services:

    ./deploy.sh base
    

    Check the startup status:

    # docker ps
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    f3e908b5989d mysql:5.7 "docker-entrypoint.s…" 6 hours ago Up 6 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp ruoyi-mysql
    090a066f03f8 redis "docker-entrypoint.s…" 6 hours ago Up 6 hours 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp ruoyi-redis
    
    

    Under normal circumstances, the redis and mysql services are normal. nacos failed to start, so don’t worry about it for the time being.

  4. Import Ruoyi SQL script

    Copy the nacos script to the mysql container:

    cd mysql/db/
    docker cp ry_20230706.sql f3e908b5989d:/
    docker cp ry_config_20220929.sql f3e908b5989d:/
    

    Enter the mysql container and connect to the mysql service

    # docker exec -it f3e908b5989d bash
    
    root@f3e908b5989d:/# mysql -uroot -ppassword
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 41
    Server version: 5.7.36 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    Create nacos library and import SQL script:

    create database `ry-config` character set utf8 collate utf8_general_ci;
    
    use ry-cloud;
    source /ry_20230706.sql;
    
    use ry-config;
    source /ry_config_20220929.sql;
    
    exit
    

    Use exit to exit the mysql client, and use exit again to exit the container.

  5. Restart nacos

    Execute the command to query the nacos container ID that failed to start:

    docker ps -a
    # return
    CONTAINER ID IMAGE
    e0e44800a523 nacos/nacos-server
    

    Restart nacos:

    docker restart e0e44800a523
    

    Observe the nacos log. Normal nacos can be started successfully:

    docker logs e0e44800a523
    
  6. Log in to nacos to modify Ruoyi microservice configuration

    Access the nacos page (nacos/nacos) through http://virtual machine IP:8848/nacos:

    Modify ruoyi-gateway-dev.yml configuration:

    spring:
      redis:
        host: localhost #Change to virtual machine IP
        port: 6379
        password:
    

    Modify ruoyi-auth-dev.yml configuration:

    spring:
      redis:
        host: localhost #Change to virtual machine IP
        port: 6379
        password:
    

    Modify ruoyi-system-dev.yml configuration:

    spring:
      redis:
        host: localhost #Change to virtual machine IP
        port: 6379
        password:
        
        ...
        
          datasource:
              master:
                driver-class-name: com.mysql.cj.jdbc.Driver
                #Change to virtual machine IP
                url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true & amp;characterEncoding=utf8 & amp;zeroDateTimeBehavior=convertToNull & amp;useSSL=true & amp;serverTimezone=GMT+8
                username: root
                password: password
    

    Modify ruoyi-gen-dev.yml configuration:

    spring:
      redis:
        host: localhost #Change to virtual machine IP
        port: 6379
        password:
      datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        # #Change to virtual machine IP
        url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true & amp;characterEncoding=utf8 & amp;zeroDateTimeBehavior=convertToNull & amp;useSSL=true & amp;serverTimezone=GMT+8
        username: root
        password: password
    

    Modify ruoyi-job-dev.yml configuration:

    spring:
      redis:
        host: localhost #Change to virtual machine IP
        port: 6379
        password:
      datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        #Change to virtual machine IP
        url: jdbc:mysql://localhost:3306/ry-cloud? useUnicode=true & amp;characterEncoding=utf8 & amp;zeroDateTimeBehavior=convertToNull & amp;useSSL=true & amp;serverTimezone=GMT+8
        username: root
        password: password
    
  7. Modify Ruoyi jar package configuration file

    Find the jar package:

    [root@localhost docker]# find ./ -name *.jar
    ./ruoyi/auth/jar/ruoyi-auth.jar
    ./ruoyi/gateway/jar/ruoyi-gateway.jar
    ./ruoyi/modules/file/jar/ruoyi-modules-file.jar
    ./ruoyi/modules/gen/jar/ruoyi-modules-gen.jar
    ./ruoyi/modules/job/jar/ruoyi-modules-job.jar
    ./ruoyi/modules/system/jar/ruoyi-modules-system.jar
    ./ruoyi/visual/monitor/jar/ruoyi-visual-monitor.jar
    

    Install vim and zip commands:

    yum install zip vim -y
    

    Take the first jar package as an example ./ruoyi/auth/jar/ruoyi-auth.jar, edit the jar package:

    vim ./ruoyi/auth/jar/ruoyi-auth.jar
    # Find bootstrap.yml and change all localhosts to virtual machine IP addresses
    ...
      cloud:
        nacos:
          discovery:
            # Service registration address
            server-addr: 192.168.22.134:8848
          config:
            # Configuration center address
            server-addr: 192.168.22.134:8848
            #Configuration file format
            file-extension: yml
            # Shared configuration
            shared-configs:
              - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
    ...
    

    The modification process of other jar packages is the same and will not be repeated.

  8. Start Ruoyi microservice

    [root@localhost docker]# ./deploy.sh modules
    

    Under normal circumstances, four container processes will be started: nginx, docker_ruoyi-modules-system, docker_ruoyi-auth, docker_ruoyi-gateway:

    [root@localhost docker]# docker ps
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    fcdbd6c56ab4 keking/kkfileview "java -Dfile.encodin…" 4 hours ago Up 4 hours 0.0.0.0:8012->8012/tcp, :::8012->8012/tcp ecstatic_jones
    127ea30c521d nginx "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, :::80->80/tcp ruoyi-nginx
    fb72aea1d703 docker_ruoyi-modules-system "java -jar ruoyi-mod…" 6 hours ago Up 6 hours 0.0.0.0:9201->9201/tcp, :::9201->9201/tcp ruoyi-modules-system
    75ebd2c9118a docker_ruoyi-auth "java -jar ruoyi-aut…" 6 hours ago Up 6 hours 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp ruoyi-auth
    4bc210701adb docker_ruoyi-gateway "java -jar ruoyi-gat…" 6 hours ago Up 6 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp ruoyi-gateway
    e0e44800a523 nacos/nacos-server "bin/docker-startup.…" 7 hours ago Up 6 hours 0.0.0.0:8848->8848/tcp, :::8848->8848/tcp, 0.0.0.0:9848-9849- >9848-9849/tcp, :::9848-9849->9848-9849/tcp ruoyi-nacos
    f3e908b5989d mysql:5.7 "docker-entrypoint.s…" 7 hours ago Up 6 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp ruoyi-mysql
    090a066f03f8 redis "docker-entrypoint.s…" 7 hours ago Up 6 hours 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp ruoyi-redis
    
  9. Modify Nginx front-end file location

    There is a problem with the location of the Ruoyi front-end page provided in the official image. Accessing the Ruoyi front-end will return 403. You need to enter the container to modify the front-end file location:

    docker exec -it 127ea30c521d bash
    cd /home/ruoyi/projects/ruoyi-ui/dist/
    mv ./* ../
    

    Move the front-end page up one directory level. This problem can also be solved by changing the nginx configuration (not tried).

  10. Visit Ruoyi address

    Turn off firewall etc.

    systemctl stop firewalld
    setenforce 0
    

    Browser access front-end address:

    http://Virtual Machine IP

    admin/admin123

4. Reference materials

  1. http://doc.ruoyi.vip/ruoyi-cloud/cloud/dokcer.html#Project deployment