docker部署vue3+express到服务器

express的dockerfile

FROM node

WORKDIR /app

COPY ./package.json /app/

RUN npm install

COPY . /app/

EXPOSE 3000

CMD node app.js

vue部分的dockerfile

FROM nginx
EXPOSE 3010
COPY /dist /usr/share/nginx/html
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

其中default.conf文件内容为:

server {
    listen       3010;
    listen	 [::]:3010;
    server_name  localhost;

    access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    location ^~ /prod-api/ {              
	    proxy_pass http://xxx.xx.xx.x:xxx/;//express运行的服务器地址  
    }

    #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拉取的nginx镜像默认配置,需要自行写一个配置去覆盖。

一些坑

我是在MacOs上开发的,docker打包的会默认为你当前运行环境。所以本地测试通过放在linux服务器会无法跑,甚至容器都无法启动。要添加制定版本去打包镜像。

docker build --platform linux/amd64 -t gorker-vue3-linux:latest .   

使用了element-plus中的Menu菜单作为Aside布局。其中:default-active属性起初为这么写的

  <el-menu
    class="el-menu-vertical-demo"
    text-color="#ffffff"
    active-text-color="#ffd04b"
    background-color="#5a3fba"
    :collapse="isCollapse"
    :default-active="this.$route.path"
    :router="true"
  >
</el-menu>

在本地运行无问题,打包到服务器上会报错 Cannot read properties of undefined (reading '$route')

解决方案为将this删除即修改为

  <el-menu
    class="el-menu-vertical-demo"
    text-color="#ffffff"
    active-text-color="#ffd04b"
    background-color="#5a3fba"
    :collapse="isCollapse"
    :default-active="$route.path"
    :router="true"
  >
</el-menu>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值