为Angular 构建Dockerfile

hmae6n7t  于 2023-01-08  发布在  Docker
关注(0)|答案(2)|浏览(133)

我在网上看了无数篇关于构建一个Docker容器来测试Angular 的文章,在所有的例子中,我都以这个错误结束:

=> ERROR [6/6] RUN  npm run build --omit=dev                                                                                                                                        
0.7s
------
 > [6/6] RUN  npm run build --omit=dev:
#10 0.687
#10 0.687 > edi-tracker@0.0.0 build
#10 0.687 > ng build
#10 0.687
#10 0.695 sh: 1: ng: Permission denied

经过大量测试,我可以看到问题是,ng从来没有安装或添加到PATH。npm命令工作正常,但当npm切换到angular-cli,它失败了。但令人费解的是,似乎没有人遇到这个错误。我的Dockerfile如下。谁能给予建议,以解决这个ng:权限被拒绝错误?

### STAGE 1: Build ###
FROM node:latest AS build  
USER node
WORKDIR /usr/src/app
COPY --chown=node:node package.json package-lock.json ./
RUN npm install
COPY --chown=node:node . .
RUN  npm run build --omit=dev
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
qcbq4gxm

qcbq4gxm1#

这是可行的:

### STAGE 1: Build ###
FROM node:latest AS build
#USER node
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY  . .
RUN npm install -g @angular/cli@14.2.1
RUN npm run build --omit=dev
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
dy1byipe

dy1byipe2#

试试这个

### STAGE 1: Build ###
FROM node:latest AS build
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist/aston-villa-app /usr/share/nginx/html

相关问题