背景:我需要构建一个 Angular 的项目,每次打镜像时都需要很长时间下载依赖,想要将依赖打包成一个单独的基础镜像,构建项目时给予这个基础镜像并使用基础镜像中的本地缓存快速构建。
FROM node
COPY ./package.json /
RUN usermod -s /bin/bash root
RUN mkdir '/npm'
RUN mkdir '/npm_cache'
RUN npm config set prefix '/npm'
RUN npm config set cache '/npm_cache'
RUN npm config set registry https://registry.npmmirror.com && npm install
RUN npm install -g @angular/cli
RUN echo "export PATH=/npm/bin:$PATH" >> ~/.bashrc
FROM junebao/ang_base AS builder
WORKDIR /ang
COPY . /ang/
RUN cp -r /node_modules .
RUN /npm/bin/ng build
FROM nginx:1.19.10-alpine AS server
COPY --from=builder /ang/dist/* /usr/share/nginx/html
EXPOSE 80
我的博客即将同步至腾讯云开发者社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=rya5sco91vd7