我正在使用dockerfile构建和运行。生成Docker文件需要10-15分钟。但npm run build需要2-3分钟.任何想法,我可以如何改进这个码头文件,以更快的构建时间。
FROM node:14.18-alpine as build
WORKDIR /usr/local/frontend
RUN npm cache clean --force
COPY ./ /usr/local/frontend/
RUN npm install
RUN npm run build --prod
# Nginx
FROM nginx:1.21-alpine
# COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/local/frontend/dist /usr/share/nginx/html
# CMD ["nginx", "-g", "daemon off;"]
EXPOSE 9020发布于 2022-01-28 08:29:42
如果首先复制package.json文件,然后执行npm install,则创建一个缓存层,其中包含所有npm包,只有在更改package.json文件时才需要刷新这些包。
我不认为cache clean会做任何事情,因为在运行它的时候,图像是一个“空白”的节点映像。
FROM node:14.18-alpine as build
WORKDIR /usr/local/frontend
RUN npm cache clean --force
COPY package.json .
RUN npm install
COPY ./ /usr/local/frontend/
RUN npm run build --prod
# Nginx
FROM nginx:1.21-alpine
# COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/local/frontend/dist /usr/share/nginx/html
# CMD ["nginx", "-g", "daemon off;"]
EXPOSE 9020https://stackoverflow.com/questions/70890656
复制相似问题