.首先编写启动脚本 start.sh
#!/bin/sh sed -i 's@<html@<html VUE_APP_URL=' "$VUE_APP_URL"'@' /usr/share/nginx/html/index.html nginx -g "daemon off ;"
2.打docker镜像的Dockerfile
Dockerfile FROM nginx:1.17.6 COPY .dist /usr/share/nginx/html COPY ./start.sh /app/ EXPOSE 8080 WORKDIR /app ENTRYPOINT ["/app/start.sh"]
3.vue的main.js配置中设置
const VUE_APP_URL = document.querySelector("html").getAttribute("VUE_APP_URL"); console.log(`${VUE_APP_URL }`); console.log(VUE_APP_URL ); console.log(process.env.VUE_APP_URL )