Dockerfile nginx vue3
FROM node:20.10.0 AS build-stage
ARG BASE_URL=http://10.10.10.10:8080
ENV VITE_APP_API_BASE_URL ${BASE_URL}
ARG envPORT=3000
ENV envPORT ${envPORT}
RUN echo ${BASE_URL}
WORKDIR /app
COPY ./package*.json ./
COPY ./default.conf ./
RUN npm config set registry https://registry.npmmirror.com
RUN ulimit -n 4096 && npm install
COPY ./ .
RUN sed -i "s/3000/$(echo $envPORT | sed 's/\//\\\//g')/g" default.conf
RUN sed -i "s!const PROD_API_URL = .*!const PROD_API_URL = \"${BASE_URL}\"!g" ./src/env/index.ts
RUN npm run build
FROM nginx:1.27.3
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY --from=build-stage /app/dist /etc/nginx/html
COPY --from=build-stage /app/default.conf /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]
EXPOSE {PORT}
default.conf
server {
listen 3000;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
# try_files $uri $uri/ /index.html;
}
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
}

浙公网安备 33010602011771号