在 Google Container Builder 上使用 Docker 构建 Angular 应用程序失败
Building Angular application with Docker on Google Container Builder fails
我正在尝试在 GCP 上使用 'Google Container Builder' 使用以下 Dockerfile 构建 Angular 应用程序,但失败并显示错误代码
### STAGE 1: Build ###
# We label our stage as ‘builder’
FROM node:8.1.4-alpine as builder
COPY package.json ./
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build.
# RUN npm cache clean
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
WORKDIR /ng-app
COPY . .
## Checking node version and that it can be accessed irectly
RUN node --version
## ng Version check
RUN $(npm bin)/ng --version
## Build the angular app in production mode and store the artifacts in dist folder
RUN node --max-old-space-size=8192 $(npm bin)/ng build --prod --aot --build-optimizer --no-progress
##RUN $(npm bin)/ng build --prod ## Fails also
### STAGE 2: Setup ###
FROM nginx:1.13.3-alpine
## Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/
## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
COPY --from=builder /ng-app/dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
我是这样启动的
stage('Build and push image with Container Builder') {
// ----------------------------------------------------------
// Apparently there is an issue with multi-stage builds on Jenkins
// Build using container builds and push to container registry (120 mins of free daily for builds included)
steps {
container('gcloud') {
dir('./AlbumFoo.Web') {
sh "PYTHONUNBUFFERED=1 gcloud builds submit --tag ${imageTagAlbumWebsite} ."
}
}
}
}
它开始获取 npm 包和所有的东西,在它实际进行构建的步骤上失败,即在
RUN node --max-old-space-size=8192 $(npm bin)/ng build --prod --aot --build-optimizer --no-progress
失败 "gcr.io/cloud-builders/docker" 失败:退出状态 139
我已修复 package.json 中的包引用冲突,包括 @angular/cli: 1.7.0 和 "@angular-devkit/build-angular": "~0.6.0"。
我也更新了 docker 文件
### STAGE 1: Build ###
# We label our stage as ‘builder’
FROM node:10.0.0 as builder
#Cleanup
RUN npm cache clean --force
#RUN rmdir node_modules /s /q
RUN npm install -g typescript@2.7.2
COPY package.json ./
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build.
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
WORKDIR /ng-app
COPY . .
## Checking node version and that it can be accessed irectly
RUN node --version
## ng Version check
RUN $(npm bin)/ng --version
##RUN npm rebuild node-sass --force
## Build the angular app in production mode and store t he artifacts in dist folder
##RUN node --max-old-space-size=8192 $(npm bin)/ng build --prod --aot --build-optimizer --no-progress
##RUN REM call npm install -g @angular/cli
RUN $(npm bin)/ng build --prod
### STAGE 2: Setup ###
# base image
FROM nginx:1.13.9-alpine
# copy artifact build from the 'build environment'
COPY --from=builder /ng-app/dist /usr/share/nginx/html
# expose port 80
EXPOSE 80
# run nginx
CMD ["nginx", "-g", "daemon off;"]
我最终创建了一个基本的 docker 图像和 运行 Dockerfile 中定义的步骤,一次一个地通过 ssh 将根本原因隔离到容器中。
我正在尝试在 GCP 上使用 'Google Container Builder' 使用以下 Dockerfile 构建 Angular 应用程序,但失败并显示错误代码
### STAGE 1: Build ###
# We label our stage as ‘builder’
FROM node:8.1.4-alpine as builder
COPY package.json ./
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build.
# RUN npm cache clean
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
WORKDIR /ng-app
COPY . .
## Checking node version and that it can be accessed irectly
RUN node --version
## ng Version check
RUN $(npm bin)/ng --version
## Build the angular app in production mode and store the artifacts in dist folder
RUN node --max-old-space-size=8192 $(npm bin)/ng build --prod --aot --build-optimizer --no-progress
##RUN $(npm bin)/ng build --prod ## Fails also
### STAGE 2: Setup ###
FROM nginx:1.13.3-alpine
## Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/
## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
COPY --from=builder /ng-app/dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
我是这样启动的
stage('Build and push image with Container Builder') {
// ----------------------------------------------------------
// Apparently there is an issue with multi-stage builds on Jenkins
// Build using container builds and push to container registry (120 mins of free daily for builds included)
steps {
container('gcloud') {
dir('./AlbumFoo.Web') {
sh "PYTHONUNBUFFERED=1 gcloud builds submit --tag ${imageTagAlbumWebsite} ."
}
}
}
}
它开始获取 npm 包和所有的东西,在它实际进行构建的步骤上失败,即在
RUN node --max-old-space-size=8192 $(npm bin)/ng build --prod --aot --build-optimizer --no-progress
失败 "gcr.io/cloud-builders/docker" 失败:退出状态 139
我已修复 package.json 中的包引用冲突,包括 @angular/cli: 1.7.0 和 "@angular-devkit/build-angular": "~0.6.0"。
我也更新了 docker 文件
### STAGE 1: Build ###
# We label our stage as ‘builder’
FROM node:10.0.0 as builder
#Cleanup
RUN npm cache clean --force
#RUN rmdir node_modules /s /q
RUN npm install -g typescript@2.7.2
COPY package.json ./
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build.
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
WORKDIR /ng-app
COPY . .
## Checking node version and that it can be accessed irectly
RUN node --version
## ng Version check
RUN $(npm bin)/ng --version
##RUN npm rebuild node-sass --force
## Build the angular app in production mode and store t he artifacts in dist folder
##RUN node --max-old-space-size=8192 $(npm bin)/ng build --prod --aot --build-optimizer --no-progress
##RUN REM call npm install -g @angular/cli
RUN $(npm bin)/ng build --prod
### STAGE 2: Setup ###
# base image
FROM nginx:1.13.9-alpine
# copy artifact build from the 'build environment'
COPY --from=builder /ng-app/dist /usr/share/nginx/html
# expose port 80
EXPOSE 80
# run nginx
CMD ["nginx", "-g", "daemon off;"]
我最终创建了一个基本的 docker 图像和 运行 Dockerfile 中定义的步骤,一次一个地通过 ssh 将根本原因隔离到容器中。