我正在按照此檔案撰寫多階段構建。
我的 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
為什么會這樣?
uj5u.com熱心網友回復:
它們是并行運行的,因為這兩個階段都不依賴于彼此。如果您這樣做只是為了了解 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 .
構建器階段在部署器階段之前執行......因為部署器使用--from=builder這意味著它依賴于構建器階段以在這種情況下復制一些檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/494060.html
