gpt4 book ai didi

node.js - Docker 构建在第一阶段之前运行第二阶段

转载 作者:行者123 更新时间:2023-12-04 18:58:42 25 4
gpt4 key购买 nike

我正在关注 documentation编写多阶段构建。
我的 Dockerfile:

FROM ubuntu:trusty
RUN apt-get update && apt-get install apt-transport-https -y
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install google-chrome-stable -y

FROM node:alpine
COPY . ./
RUN npm install
RUN npm run lighthouse
我正在尝试在运行 Google Lighthouse 之前将 Google Chrome 安装到图像上。但是,根据日志,构建首先运行第二阶段。
 => CACHED [stage-1 2/4] COPY . ./                                                                                   0.0s 
=> [stage-1 3/4] RUN npm install 100.8s
=> ERROR [stage-1 4/4] RUN npm run lighthouse
为什么会这样?

最佳答案

它们是并行运行的,因为两个阶段都不依赖于彼此。如果您这样做只是为了了解 docker 中的多阶段构建;这是一个示例:

FROM ubuntu:trusty
RUN apt-get update && apt-get install apt-transport-https -y
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install google-chrome-stable -y

FROM someangularapp:alpine as builder
COPY . ./
RUN npm install
RUN ng build

##Above stage generates a `dist` folder in its workspace

FROM nginx:latest as deployer
COPY --from=builder /app/dist /usr/share/nginx/html/
现在无论何时运行: docker build -t someimagename --target deployer .builder 阶段在 deployer 阶段之前执行...因为 deployer 使用 --from=builder这意味着在这种情况下,它依赖于构建器阶段来复制一些文件。

关于node.js - Docker 构建在第一阶段之前运行第二阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72639734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com