How can I exclude the @angular/cli package from the npm-install process during the construction of a Docker image?



  • I'm starting a project that will make use of Angular.js and Node.js and will be contained in a Docker image. In me Dockerfile I have indicated that Docker must execute the instruction RUN npm install to configure my project when Docker builds the image. This is a part of the image construction logs:

    Step 4/10 : RUN npm install
    ---> Running in 90d567c905d4
    

    > @angular/cli@6.0.3 postinstall /usr/src/app/node_modules/@angular/cli
    > node ./bin/ng-update-message.js

    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

    added 295 packages in 12.979s

    I installed the package@angular/cli with npm in my operating system and I don't want the package @angular/cli is installed on my project when Docker executes RUN npm installThat makes my image heavier.

    How I can exclude the package @angular/cli of the process npm-install during the construction of a Docker image?

    To try to solve this I use this instruction in my Dockerfile:

    RUN npm uninstall @angular/cli

    But it doesn't solve my problem.



  • The only way you don't install a package with the command npm install is that this one is not in the file package.json or that the package is specified as a dependency dev and install the production packages. If the goal is to implement the deployment using docker would create a docker swarm in which in one container would be the backend (NodeJS) and in the other container would find an image of NGINX with the angular solution. They could also be contained both in the same container but I advise to separate the project into two, one containing Angular and the other containing NodeJS.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2