skip to Main Content

I’m following countless articles on the web for building a docker container for testing angular. In all examples, I end up with this error:

 => 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 > [email protected] build
#10 0.687 > ng build
#10 0.687
#10 0.695 sh: 1: ng: Permission denied 

After testing a lot, I can see that the problem is, ng is never installed or added to PATH. npm commands work fine, but when npm hands off to angular-cli, it fails. But it’s puzzling that nobody seems to encounter this error. My Dockerfile is below. Can anyone give suggestions to resolve this ng: Permission denied error?

### 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

2

Answers


  1. Chosen as BEST ANSWER

    this works:

    ### 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/[email protected]
    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
    

  2. Try this on

    ### 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search