若 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
以上 Dockerfile
在 docker build .
时会遇到错误:
解决方案
解决方案很简单,将 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
标签: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