3

I tried to run npm ci command using the same package.json and package-lock.json files in three different environments:

  • docker host machine - takes ~27s to complete
  • inside a docker container - takes ~32s to complete
  • during building a docker image - takes ~163s to complete

I wonder why it takes much more time to install packages when building an image. What the difference between running commands when building an image and when running commands inside a container manually? Perhaps it's related to the amount of resources (CPU, Memory) docker uses when building an image?

I use the same node and npm version in all three environments. Docker host is a Windows Server 2019 VM that has 2 virtual CPUs and 2GB of memory. Docker version is 18.09.2.

  • "inside a docker container": was the `node_modules` directory located on a _docker volume_ or was it on the container file system itself? – Thomasleveil Mar 10 '19 at 18:00
  • @Thomasleveil it's on the container file system. I tried to replicate behaviour of building an image. If I correctly understand running commands inside container and then calling `docker commit` is not that different from the process of building an image (considering there is no image cache). Please, correct me if I'm wrong. My another theory is that it runs that slow because of the image caching process. If that's the case I'd like somebody to confirm it. – Pavels Ahmadulins Mar 10 '19 at 19:16
  • 1
    beware that the image produced by `docker commit` won't have the files that are located in a _docker volume_ in the container. Writing files to the docker file system is known to be slower than writing files on a docker volume, hence my previous question. CPU and memory: nope, AFAIK there is no limitation while building an image. It might be quicker in a container if you run `npm ci` multiple time due to npm modules caching – Thomasleveil Mar 10 '19 at 21:03

0 Answers0