当前位置: 首页 > article >正文

Docker 部署Spring boot + Vue(若依为例)

首先我们要在docker中安装好环境镜像

jdk.  mysql.  redis. nginx 镜像安装我们在上一篇文章中已说明,请大家自行查看

下面我介绍部署步骤

  • 部署后台jar

在你的工作目录下新建application 用来存放后台jar包

1.将打好的jar包上传

2.编写Dockerfile文件,上传到jar同目录

#Dockerfile
#指定镜像
FROM openjdk:8 

#后续指定工作目录
WORKDIR /app
#添加JAR文件到容器中
COPY ruoyi-admin.jar ./application.jar
#设置环境变量
ENV TZ Asia/Shanghai
ENV JAVA_OPS -Duser.timezone=Asia/Shanghai
#运行端口
EXPOSE 8090
#启动命令
ENTRYPOINT ["java","-Dfile.encoding=utf-8","-D-Xms2g -Xmx2g","-Dserver.port=8090","-Dspring.profiles.active=druid","-Djava.security.egd=file:/dev/./urandom","-jar","./application.jar"]

  •  部署Vue前台

在上篇文章中,我们已经将nginx的html目录和config目录挂载到了我们新建的工作目录/usr/local/workspace/nginx下

1.将我们前台打的dist下的文件上传到/usr/local/workspace/nginx/html目录下

2.编辑我们/usr/local/workspace/nginx/conf下的nginx.conf文件,配置内容如下


user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


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/share/nginx/html;
                        try_files $uri $uri/ /index.html last; 
            index  index.html index.htm;
        }
        #跨域配置
        location /prod-api/{
                proxy_pass http://172.31.3.64:8090;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

  • 编辑docker-compose.yml文件
version: "3.3"
services:
  redis:
    image: redis
    restart: always
    ports:
      - "6379:6379"
    volumes:
      - ./redis/redis.conf:/etc/redis/redis.conf
      - ./redis/data:/data
    command: redis-server /etc/redis/redis.conf  
  nginx:
    # 镜像名 如果需要指定版本 就把 latest 换成版本号
    image: nginx:1.25 
    # 容器名
    container_name: nginx-web
    # 重启策略
    restart: always
    # 端口映射
    #network_mode: host
    ports:
      - 80:80
    volumes:
      - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/html:/usr/share/nginx/html
      - ./nginx/log:/var/log/nginx # 将Nginx的日志目录挂载到宿主机
    privileged: true # 这个必须要,解决nginx的文件调用的权限问题
  api:
    build: ./application
    ports:
      - '8090:8090'
    container_name: ruoyi-api
    restart: always
    volumes:
      - ./logs:/opt/logs

关于Dockerfile和Docker Compose的详细内容大家可以到菜鸟教程学习

安装部署中出现的错误:

1.502没有权限,并且加载不出验证码

这个是nginx配置代理的问题,大家就仔细检查一下,nginx.conf配置文件就行,我是没有添加图里我框住的内容,加上就行了

 2.加上配置后,又报了一个404,还是没有显示验证码

404就是请求路径不对

我这里的原因是我前台vue打的是prod  的包,后台jar包我直接用的若依的配置文件打的包,默认没有项目前缀,所有一直报404,加上前缀就好了

浏览器测试

 


http://www.kler.cn/a/585566.html

相关文章:

  • Linux系统下安装Gedit文本编辑器的完整指南
  • C++能力测试题
  • 深入 Python 网络爬虫开发:从入门到实战
  • 完善 Django 框架以实现传递视频、图片给算法模块进行识别分析
  • 防止手机验证码被刷:React + TypeScript 与 Node.js + Express 的全面防御策略
  • WebLogic XMLDecoder反序列化漏洞(CVE-2017-10271)深度解析与实战复现
  • JVM 的不同组成部分分别有什么作用?
  • URL 中的参数通常用于跟踪和传递信息,特别是在在线广告和营销活动中。
  • 鸿蒙初学者学习手册(HarmonyOSNext_API14)_UIContext(@ohos.arkui.UIContext (UIContext))
  • tensorflow与torch并行读取数据机制
  • 浅谈StarRocks数据库简介及应用
  • 阿里巴巴发布 R1-Omni:首个基于 RLVR 的全模态大语言模型,用于情感识别
  • ZooKeeper的五大核心作用及其在分布式系统中的关键价值
  • Redis 常用数据类型
  • 在 Qt 中自定义控件样式:使用 QProxyStyle 代理和修改绘制元素
  • AnyAnomaly: 基于大型视觉语言模型的零样本可定制视频异常检测
  • 回文字串(信息学奥赛一本通-2044)
  • 网络华为HCIA+HCIP网络层协议
  • 【雅思播客08】I‘m sorry. I love you.
  • 最新AI智能体Prompt指令预设词分享+GPTs应用使用