Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

448
Visualizações
Confusion with node_modules being ignored by .dockerignore

Thought I'd just wanted to share this. So I am testing creation of a docker image/container with a nodejs app usiung Dockerfile. Everything went smoothly, until I tried to add the .dockerignore file, where I listed the following files in it, expecting that they won't get copied into the docker image:

node_modules 
dockerignore 
Dockerfile

And here is my Dockerfile:

FROM node:latest
WORKDIR /app
ADD . .
RUN npm install
CMD node index.js

So I trashed and rebuilt my image with the existing Dockerfile and the new .dockerignore file. After the creation, I ran docker run -it --entrypoint sh <image name> to check if those files/folders do not appear anymore.

Dockerfile and .dockerignore are gone. But node_modules folder is still there.

Took me a while to "realize" that MAYBE the node_modules folder in the image is created by the Dockerfile's npm install step, not the folder copied from the host anyway.

Am I right?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

So I got the answer based on tkausl and David Maze's comments (thanks guys!) .

The node_modules inside the image is generated from the Dockerfile 'npm install' step.

And as for the question:

if .dockerignore does not include node_modules, Dockerfile would have overwritten node_modules anyway? So why bother to put node_modules inside the .dockerignore file?

the comment I received was that if I left out the node_modules from the .dockerignore file, then the docker build process would have slowed down due to unnecessary copying of the node_modules, PLUS the image would have been larger.

Therefore, the prudent thing is to keep node_modules inside .dockerignore file to achieve more efficiency in the docker build process.

UPDATE: I did try to run the scenario with the node_modules removed from .dockerignore file, and the image is showing 940MB, whereas creating the image with node_modules inside the .dockerignore file - though the process may be more efficient - the output image is 942MB (2MB larger).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda