发布时间:2024-11-10 11:01
1. 安装docker
//docker 安装依赖
yum -y install yum-utils device-mapper-persistent-data lvm2 container-selinux
//配置docker库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
//安装docker
yum install -y docker
//查看docker是否安装成功
yum list installed | grep docker
//设置开机自启并启动docker
systemctl enable docker
//启动docker服务
systemctl start docker
//查看是否启动成功
systemctl status docker
// docker默认网桥
172.17.0.1
2.打ruoyi微服务jar包,127.0.0.1:8848全部改成172.17.0.1:8848
3.Xftp 创建/usr/local/ruoyi文件夹,再创建system,auth,gateway三个子文件夹,上传jar包
4.创建Dockerfile文件,内容如下,分配到三个子文件夹里,名称要改
FROM java:8
ADD ruoyi-auth-2.4.0.jar auth.jar
ENTRYPOINT [\"java\",\"-jar\",\"auth.jar\"]
5. 创建docker镜像,进入各子目录,执行
cd /usr/local/ruoyi/auth
docker build -t auth .
cd /usr/local/ruoyi/gateway
docker build -t gateway .
cd /usr/local/ruoyi/system
docker build -t system .
6.运行docker
docker run -d -p 9201:9201 system
docker run -d -p 9200:9200 auth
docker run -d -p 8080:8080 gateway
7.Xftp新建/usr/local/ruoyi/ui文件夹,npm打正式包,dist文件夹放入此目录
8.修改nginx.conf如下
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 /usr/local/ruoyi/ui/dist;
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://localhost:8080/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
重启nginx,正常使用