Docker

多阶段构建DockerFile

  1. FROM node:16-alpine3.11 as builder
  2. WORKDIR '/build'
  3. COPY myaccount ./myaccount
  4. COPY resources ./resources
  5. COPY third_party ./third_party
  6. WORKDIR '/build/myaccount'
  7. RUN npm install
  8. RUN npm rebuild node-sass
  9. RUN npm run build
  10. RUN ls /build/myaccount/dist
  11. FROM nginx
  12. EXPOSE 80
  13. COPY --from=builder /build/myaccount/dist /usr/share/nginx/html

multi-stage build 的支持

在使用docker 进行多阶段构建镜像时,有如下报错;查看资料是docker 17.05 才开始支持多阶段构建。
image.png

  1. ERROR: Service 'myaccount-service' failed to build : Error parsing reference: "node:16-alpine3.11 as builder" is not a valid repository/tag: invalid reference format

解决

卸载低版本Docker

  1. yum remove docker
  2. yum remove docker-common
  3. yum remove docker-client

安装最新版Docker

  1. curl -fsSL https://get.docker.com/ | sh
  2. systemctl restart docker
  3. systemctl enable docker

image.png

之后再执行构建命令发现可以成功执行

image.png