Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
npm install doesn't work in Docker

This is my Dockerfile:

FROM node:7

RUN apt-get update && apt-get install -y --no-install-recommends \
    rubygems build-essential ruby-dev \
    && rm -rf /var/lib/apt/lists/*

RUN npm install -gq gulp bower

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app

RUN npm install

CMD ["gulp", "start:dev"]

When I build the image, the npm install command executes with little output and really quickly. I actually build it through docker-compose which does have a volume mounted - and I cannot see the node_modules folder being created on my hose. When I launch a container on this image, I can see there is no node_modules folder. I then execute npm install and things start working - it takes 2-3 minutes to install all the packages and the node_modules folder is indeed created.

What is happening here? What am I doing wrong? Why doesn't npm install work at build time, but then it works at run time?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

The npm install should have worked based on your Dockerfile. You can see the created files if you run the image without a mounted volume (DIRNAME: where your docker-compose.yml is located):

docker run --rm -it DIRNAME_node ls -ahl /usr/src/app

With docker build, all data is stored in the image. So, it's intended that you don't see any files created on your host.

If you mount a volume (generally in Linux, also in a Docker container), it overlays the directory. So you can't see the node_modules created in the build step.

I suggest you do your tests based on the Docker image itself and don't mount the volume. Then you have an immutable Docker image which is better for deployment.

about 4 years ago · Santiago Trujillo Denunciar

0

Also copying up the source and running npm install means that whenever the source code changes, the npm install step cache becomes invalid.

Instead, separate the steps/caches like so;

COPY package*.json ./
RUN npm install
about 4 years ago · Santiago Trujillo Denunciar

0

On Windows 10 I was having the same issue reported in this question and after some research I've found a question with the necessary steps to solve the problem.

In short, the main problem is that during the install wizard I've selected the option "Windows as containers".

To solve the issue:

1) Switch to Linux Containers: On taskbar, right click on docker icon and click on the option as presented bellow:

enter image description here

2) Disable "Experimental Features" on Command Line: Open docker/settings and click on Command Line:

enter image description here

3) Disable Experimental setting on configuration file:: On docker/settings, click on Docker Engine and certify that experimental is set to false:

enter image description here

The question where I found the solution was related to another problem I was facing when trying to build docker images: Unspecified error (0x80004005) while running a Docker build. Both problems were related to the same issue: when installing docker for the first time I've selected the option "windows as containers". Hope it helps. Cheers

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda