VUE应用打包Docker参考

使用nginx反向代理,将80端口的流量分流到web资源目录
使用envsubst修改nginx配置文件, 通过环境变量SERVER_URI调整后端URI


  • Dockerfile
FROM dggecr01.huawei.com:80/scan-engine/node:14.7.0 as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY ./ .
RUN npm run build_pro

FROM dggecr01.huawei.com:80/scan-engine/nginx:latest as production-stage
COPY --from=build-stage /app/dist /etc/nginx/html/web/
COPY nginx-base.conf ./
WORKDIR /
EXPOSE 80
ENTRYPOINT /bin/sh -c "envsubst < nginx-base.conf > /etc/nginx/conf.d/default.conf; nginx -g 'daemon off;'"
  • nginx-base.conf
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location /web/ {
        root   /etc/nginx/html;
        error_page 404 /web/index.html;
    }


    location /api/ {
        proxy_pass ${SERVER_URI}/;
        proxy_http_version 1.1;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

你可能感兴趣的:(VUE应用打包Docker参考)