多阶段构建DockerFile
FROM node:16-alpine3.11 as builder
WORKDIR '/build'
COPY myaccount ./myaccount
COPY resources ./resources
COPY third_party ./third_party
WORKDIR '/build/myaccount'
RUN npm install
RUN npm rebuild node-sass
RUN npm run build
RUN ls /build/myaccount/dist
FROM nginx
EXPOSE 80
COPY --from=builder /build/myaccount/dist /usr/share/nginx/html
multi-stage build
的支持
在使用docker 进行多阶段构建镜像时,有如下报错;查看资料是docker 17.05 才开始支持多阶段构建。
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
yum remove docker
yum remove docker-common
yum remove docker-client
安装最新版Docker
curl -fsSL https://get.docker.com/ | sh
systemctl restart docker
systemctl enable docker