[Docker] Benefits of Multi-stage Builds

The benfits of multi-stage builds:

  • Avoid manual creation of intermediate images
  • Reduce complexity
  • Selectively copy artifacts from one stage to another
  • Smaller final image size
// nginx.prod.dockerfile
##### Stage 1
FROM node:latest as node
LABEL author="ZWT"
WORKDIR /app
# Copy the package.json to working dir
COPY package.json package.json
# install FE packages
RUN npm install
# copy all the code to the working dir
COPY . .
# start ng build -- prod
RUN npm run build -- --prod

##### Stage 2
FROM nginx:alpine
VOLUME /var/cache/nginx
COPY --from=node /app/dist /usr/share/nginx/html
COPY ./config/nginx.conf /etc/nginx/conf.d/default.conf

Run build:

docker build -t nginx-angular -f nginx.prod.dockerfile .

猜你喜欢

转载自www.cnblogs.com/Answer1215/p/10759402.html