【docker】部署项目spirngboot+vue

一、Springboot部分

pom文件中必须要有<build>标签

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

点击package打包

在target文件夹可以找到jar包

 

 编写dockerfile

【前提:虚拟机要安装好java linux安装java步骤_马小瑄的博客-CSDN博客_linux 安装java

#复制文件到容器
From java:8
#复制文件到容器
ADD bucao_springboot-0.0.1-SNAPSHOT.jar /mgcboot.jar
#声明需要暴露的端
EXPOSE 9090
#配置容器启动后执行的命令
ENTRYPOINT ["java","-jar","mgcboot.jar"]

最后,将jar包和dockerfile放到虚拟机的某个文件夹中,并在文件夹运行docker指令

生成镜像:docker build -t bucaoboot .

运行镜像:docker run --name bucaoboot -p 9090:9090 -d bucaoboot

注意生成镜像命令的最后有个点 .

二、vue打包部署

首先要安装好nginx 手把手教你,docker安装nginx_steven_cici的博客-CSDN博客 

修改好vue中的request.js和vue.config.js等和端口相关的文件

运行 npm run build命令,会生成一个dist文件夹

把dist文件夹放到虚拟机上

编写default.conf

注意:中间有 /api是代理地址【后端访问地址】,按自己情况修改

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    access_log  /var/log/nginx/host.access.log  main;
    error_log  /var/log/nginx/error.log  error;

  location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
    location /api{
        proxy_pass http://你的ip:你的后端端口;}
    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
     error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}


编写docker文件

FROM nginx

RUN rm /etc/nginx/conf.d/default.conf

ADD default.conf /etc/nginx/conf.d/

COPY dist/ /usr/share/nginx/html/

重复上面生成镜像、运行镜像指令即可

猜你喜欢

转载自blog.csdn.net/kanseu/article/details/125863616