1

I'm trying to run Docker services, one of them is angular services described below:

Dockerfile-angular:

FROM node:14
WORKDIR /usr/src/app
RUN mkdir /youngtalentreturn
COPY ./venv_youngtalentreturn_frontend/project /youngtalentreturn/
RUN npm cache clean --force
RUN npm install
EXPOSE 3000 4200
CMD [ "npm", "start" ]

docker-compose.yml:

angular:
container_name: youngtalentreturn_angular_ctnr
build:
  context: .
  dockerfile: Dockerfile-angular
restart: unless-stopped
volumes:
  - ./venv_youngtalentreturn_frontend/project:/usr/src/app
depends_on:
  - postgres
  - django
ports:
  - 3000:3000
  - 4000:4200
networks:
  - youngtalentreturn-ntwk

But throws an error:

youngtalentreturn_angular_ctnr | 
youngtalentreturn_angular_ctnr | > project@0.0.0 start /usr/src/app
youngtalentreturn_angular_ctnr | > ng serve --host 0.0.0.0
youngtalentreturn_angular_ctnr | 
youngtalentreturn_angular_ctnr | sh: 1: ng: not found
youngtalentreturn_angular_ctnr | npm ERR! code ELIFECYCLE
youngtalentreturn_angular_ctnr | npm ERR! syscall spawn
youngtalentreturn_angular_ctnr | npm ERR! file sh
youngtalentreturn_angular_ctnr | npm ERR! errno ENOENT
youngtalentreturn_angular_ctnr | npm ERR! project@0.0.0 start: `ng serve --host 0.0.0.0`
youngtalentreturn_angular_ctnr | npm ERR! spawn ENOENT
youngtalentreturn_angular_ctnr | npm ERR! 
youngtalentreturn_angular_ctnr | npm ERR! Failed at the project@0.0.0 start script.
youngtalentreturn_angular_ctnr | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
youngtalentreturn_angular_ctnr | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
youngtalentreturn_angular_ctnr | 
youngtalentreturn_angular_ctnr | npm ERR! A complete log of this run can be found in:
youngtalentreturn_angular_ctnr | npm ERR!     /root/.npm/_logs/2021-07-26T15_48_26_330Z-debug.log

Could anybody help me, please?

  • 1
    Because you are mounting over _/usr/src/app_ the _node_modules_, created by `npm install` in your Dockerfile, is also overwritten. You should create an [`ENTRYPOINT`](https://docs.docker.com/engine/reference/builder/#entrypoint) that does `npm install` then `npm start`. – β.εηοιτ.βε Jul 26 '21 at 15:59
  • Does this answer your question? [Docker-compose: node\_modules not present in a volume after npm install succeeds](https://stackoverflow.com/questions/30043872/docker-compose-node-modules-not-present-in-a-volume-after-npm-install-succeeds) – β.εηοιτ.βε Jul 26 '21 at 16:03
  • How docker-compose.yml and Dockerfile-angular should they be ? – Alberto Sanmartin Martinez Jul 26 '21 at 16:24
  • 1
    I'd generally recommend a path that deletes the `volumes:` instead, so you're running the code that's actually built into the image. Make sure the `WORKDIR` and the destination of the `COPY` match; the easiest way to do this is to put `WORKDIR` first and then `COPY package.json .` with the current directory as the destination. – David Maze Jul 26 '21 at 16:55
  • Yes indeed, if you want to make something for a "fixed" environment, then it would be best to follow the advices of @DavidMaze. Now if you want a "lively" feedback as you develop on that application, then the duplicated answer might be a good hint on how to approach it. – β.εηοιτ.βε Jul 26 '21 at 17:25

1 Answers1

0

Try running the following Dockerfile code for your angular project
Get your appname from the package-lock.json file of you angular project

# Stage 1
FROM node:latest as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build  --prod
# Stage 2
FROM nginx:alpine
COPY --from=node /app/dist/{app-name} /usr/share/nginx/html