SpringBoot+Vue前后端分離項(xiàng)目在Linux系統(tǒng)中基于Docker打包發(fā)布,并上傳鏡像到阿里鏡像私倉(cāng)
一、Java項(xiàng)目基于Docker打包發(fā)布
1.打包應(yīng)用,將打好的jar包放到我們的linux系統(tǒng)中
//跳過(guò)測(cè)試類(lèi),更快打包。也可以直接雙擊側(cè)邊欄maven里面的package打包
mvn clean package -DskipTests
將打好的jar包放到咱們opt目錄下的自定義文件夾內(nèi)
2.新建dockerfile
FROM openjdk:8
#設(shè)置工作目錄
WORKDIR /opt
#COPY wms-app-1.0-SNAPSHOT.jar /workspace/app.jar
ADD wms-app-1.0-SNAPSHOT.jar app.jar
#配置容器暴漏的端口
EXPOSE 8080
#查看是否已經(jīng)copy進(jìn)去
RUN ls
#java App
ENTRYPOINT ["java","-jar","app.jar"]
3.打包鏡像
docker build -t wmsapp:v1 .
//最后有一個(gè)點(diǎn)不要忘了
打包成功后
4.測(cè)試運(yùn)行
–rm 代表退出之后,容器移動(dòng)刪除
//指定在Linux宿主機(jī)3999端口運(yùn)行,這樣可以在電腦主機(jī)瀏覽器進(jìn)行訪問(wèn)
docker run -d -p 3999:8080 wmsapp:v1
可以看到成功啟動(dòng)了服務(wù)
5.上傳鏡像到阿里云免費(fèi)私倉(cāng)
阿里云免費(fèi)私倉(cāng)
創(chuàng)建好自己的鏡像倉(cāng)庫(kù)后會(huì)顯示操作指南
身份登錄
$ docker login --username=fpl1116 registry.cn-beijing.aliyuncs.com
將鏡像推送到Registry
$ docker tag [ImageId] registry.cn-beijing.aliyuncs.com/fpl-erp/wms-project:[鏡像版本號(hào)]
$ docker push registry.cn-beijing.aliyuncs.com/fpl-erp/wms-project:[鏡像版本號(hào)]
可以在鏡像倉(cāng)庫(kù)中進(jìn)行查看
拉取鏡像
$ docker pull registry.cn-beijing.aliyuncs.com/fpl-erp/wms-project:[鏡像版本號(hào)]
二、Vue項(xiàng)目打包到docker鏡像
1.編譯打包前端項(xiàng)目將打包生成的dist文件夾復(fù)制到咱們的wms-web文件夾內(nèi)
npm run build
2 前端項(xiàng)目 nginx的配置文件default.conf 和 dockerfile
default.conf
upstream wms-app {
server 192.168.11.87:3999 ;
}
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html; #解決單頁(yè)面找不到路徑問(wèn)題 404
}
location /api {
proxy_pass http://wms-app; #可以配置多個(gè)下游服務(wù),具有負(fù)載功能
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
1.root:設(shè)置靜態(tài)根目錄為 /usr/share/nginx/html
2. index:設(shè)置目錄的默認(rèn)文件為 index.html 、index.htm、index.php
3. try_files:設(shè)置文件查找規(guī)則為 $uri $uri/ /index.html。即3個(gè)規(guī)則,先從 $uri 查找,再?gòu)?u r i / 目錄中查找,最后查找 / i n d e x . h t m l 。
dockerfile
FROM nginx
COPY dist /usr/share/nginx/html
RUN rm -f /etc/nginx/conf.d/default.conf
#ADD default.conf /etc/nginx/conf.d/default.conf
COPY default.conf /etc/nginx/conf.d/default.conf
3.構(gòu)建鏡像(同后端)
docker build -t wmsweb:v1 .
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-854341.html
4.運(yùn)行測(cè)試
docker run -d -p 3888:80 wmsweb:v1
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-854341.html
到了這里,關(guān)于SpringBoot+Vue前后端分離項(xiàng)目在Linux系統(tǒng)中基于Docker打包發(fā)布,并上傳鏡像到阿里鏡像私倉(cāng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!