当我尝试构建以下Dockerfile时,将引发错误。
我也尝试使用RUN命令来全局安装angular / cli并直接用另一个RUN ng build --prod
调用,但是会发生相同的错误。
Dockerfile
FROM node:12.17.0-alpine AS build-angular
WORKDIR /src
COPY webui/* webui/
WORKDIR /src/webui
RUN ["npm", "install"]
RUN ["npm", "run", "build"]
构建错误输出
Step 6/6 : RUN ["npm", "run", "build"]
---> Running in 0fb33e92b742
> webui@0.0.0 build /src/webui
> ng build --prod
An unhandled exception occurred: The /src/webui/src/environments/environment.prod.ts path in file replacements does not exist.
See "/tmp/ng-fiLpfO/angular-errors.log" for further details.
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! webui@0.0.0 build: `ng build --prod`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the webui@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-05-28T11_18_53_532Z-debug.log
The command 'npm run build' returned a non-zero code: 1
来自angular.json的摘录
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
最佳答案
我必须从COPY行中删除*。
以下DOCKERFILE起作用:
FROM node:12.17.0-alpine AS build-angular
WORKDIR /src
COPY webui ./
RUN ["npm", "install"]
RUN ["npm", "run", "build"]
如Dockerfile reference中所述,不需要*
If is a directory, the entire contents of the directory are copied, including filesystem metadata.
关于node.js - 在Docker中构建Angular会抛出 “environment.prod.ts path in file replacements does not exist”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62063567/