2

i am trying to dockerize my angular app and i am getting an error("sh: 1: ng: Permission denied") when i am running the container. More specific my dockerfile is

   # Create image based on the official Node 6 image from dockerhub
   FROM node:8.10.0

   # Create a directory where our app will be placed
   RUN mkdir -p /app

   # Change directory so that our commands run inside this new directory
   WORKDIR /app

   # Copy dependency definitions
   COPY package.json /app

   # Install dependecies
   RUN npm install

   # Get all the code needed to run the app
   COPY . /app

   # Expose the port the app runs in
   EXPOSE 4200

   # Serve the app
   CMD ["npm", "start"]

Firstly i create docker image successfully but when i am going to run it i am getting the error above.

enter image description here

The docker running to a remote server with centos operating system.The simple solution i think is to change the rights of start script but i dont know how i can do that.I will appreciate anything help.

2 Answers 2

1

I find the solution ,just add to Dockerfile the lines below

 Run chmod 775 app/node_modules/.bin/ng

 Run chmod 775 app/node_modules/.bin/ng.cmd

The error occurs because i didnt gave permission to theese scripts.

Sign up to request clarification or add additional context in comments.

1 Comment

Were you able to get your app to run? I am able to have my app start but when I go to the localhost of the server with port 4200 I get a "refused to connect error".
1

I was able to launch the app after adding below two steps to Dockerfile:

  1. RUN npm install -g angular/cli
  2. CMD ng serve --host 0.0.0.0

Final Dockerfile looks like below:

FROM node:latest
RUN mkdir -p /App
WORKDIR /App
COPY . /App
RUN npm install -g @angular/cli
RUN npm install
EXPOSE 4200
CMD ng serve --host 0.0.0.0`

How to build docker file?

docker build --rm -f "Dockerfile" -t <tag_name> .

How to run docker image?

docker run -p 4200:4200 <image_id>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.