首页 > 其他分享 >修复 docker build 错误 "ERROR: No build stage in current context"

修复 docker build 错误 "ERROR: No build stage in current context"

时间:2022-10-18 19:00:27浏览次数:43  
标签:package APP No current json build HOME app

docker build 时遇到了错误 "ERROR: No build stage in current context",则有可能是没有将 FROM 命令语句放置在第一行。

问题

例如,Dockerfile 文件如下:

MAINTAINER FengYin Xu
# builder stage
FROM node:16-alpine as builder
ARG APP_HOME=/home/web/app
# Create app directory
WORKDIR ${APP_HOME}
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ${APP_HOME}/
RUN npm install
# build production package
COPY . ${APP_HOME}/
RUN npm run build

以上 Dockerfiledocker build . 时会遇到错误:
image

解决方案

解决方案很简单,将 FROM 命令语句移动到最前面,作为第一行即可。

# builder stage
FROM node:16-alpine as builder
MAINTAINER FengYin Xu
ARG APP_HOME=/home/web/app
# Create app directory
WORKDIR ${APP_HOME}
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ${APP_HOME}/
RUN npm install
# build production package
COPY . ${APP_HOME}/
RUN npm run build

image

标签:package,APP,No,current,json,build,HOME,app
From: https://www.cnblogs.com/astrofeyx/p/fix-docker-error-no-build-stage-in-current-context.htm

相关文章