11

I have an angular app which I dockerized together with nginx. My dockerfile:

FROM node:8.11.3 as node

WORKDIR /app

COPY package.json /app/

RUN npm install
COPY ./ /app/

ARG env=prod

RUN npm run build -- --prod --environment $env

FROM nginx:1.13

COPY --from=node /app/dist/ /usr/share/nginx/html

RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf

EXPOSE 4200
CMD ["npm", "start"]

I build my docker image but when I start docker run I get following error message:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"npm\": executable file not found in $PATH": unknown.

If I remove the last command from my Dockerfile (CMD ["npm","start"] I can run my docker image - it works. But I guess I need the last command so I can deploy and run my app in AWS. Also 'CMD npm start' doesnt work.

I have seen a couple of post about similar issues but non of the solutions worked for me.

UPDATE:

I removed the last line - CMD npm start. ECS is now trying to start my task - but it stops with exit code 1 and no further comments. Any idea?

Thanks, Michael

11
  • When running an Angular app, you shouldn't use npm start. That command is for creating a dev server to use while developing. Take a look at angular.io/guide/deployment. Also, if you want to run it in AWS, it would be much cheaper to serve it as static content instead of as a Docker image Commented Jul 14, 2018 at 10:04
  • What is the right way to start it? If I use CMD["ng", "serve", "-H", "0.0.0.0"] I get the same error message. Commented Jul 14, 2018 at 10:06
  • Hi, you mean I shouldnt use docker at all for AWS? Commented Jul 14, 2018 at 10:08
  • As far as understood, you second FROM instruction overrides first one, so at the moment when CMD is run, no npm executable available. Please check this: stackoverflow.com/questions/33322103/… Commented Jul 14, 2018 at 10:09
  • Not at all, there are times when Docker in AWS is great, but using Docker to serve Angular is really over the top. Once built, Angular is just a series of static files, and it would be much cheaper to use cloudfront or S3 static hosting Commented Jul 14, 2018 at 10:09

1 Answer 1

4

The nginx docker image doesn't contain npm. You'll need to use node:latest or node:alpine which contains npm.

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

2 Comments

Docker file contains multiple FROM clauses (one is node, other is nginx) - that part is probably not handled correctly.
why would he want to change to an image that has no nginx? that makes no sense, this answer makes no sense. He's asking how can he get npm and yarn working on the nginx container. If it's not there then maybe he needs to install both npm and yarn

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.