🌐
GitHub
gist.github.com › allanchua101 › 0ff808ea0aa3d6db7fd5a6b6e004fec1
.dockerignore file for Node JS · GitHub
.dockerignore file for Node JS. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › RisingStack › kubernetes-nodejs-example › blob › master › .dockerignore
kubernetes-nodejs-example/.dockerignore at master · RisingStack/kubernetes-nodejs-example
Node.js example application with Kubernetes and CircleCI config - kubernetes-nodejs-example/.dockerignore at master · RisingStack/kubernetes-nodejs-example
Author   RisingStack
🌐
GitHub
github.com › BretFisher › node-docker-good-defaults › blob › main › .dockerignore
node-docker-good-defaults/.dockerignore at main · BretFisher/node-docker-good-defaults
sample node app for Docker examples. Contribute to BretFisher/node-docker-good-defaults development by creating an account on GitHub.
Author   BretFisher
🌐
GitHub
github.com › goldbergyoni › nodebestpractices › blob › master › sections › docker › docker-ignore.md
nodebestpractices/sections/docker/docker-ignore.md at master · goldbergyoni/nodebestpractices
On top of this include a .dockerignore file that acts as the last safety net that filters out unnecessary folders and potential secrets. Doing so also boosts the build speed - By leaving out common development folders that have no use in production ...
Author   goldbergyoni
🌐
Medium
medium.com › @bounouh.fedi › mastering-the-dockerignore-file-boosting-docker-build-efficiency-398719f4a0e1
Mastering the .dockerignore File: Boosting Docker Build Efficiency | by Fedi Bounouh | Medium
November 9, 2024 - It works much like .gitignore: • Each line defines a file or directory to ignore. ... • You can use ! to negate a pattern, which means including certain files even if their parent directory is excluded.
🌐
GitHub
github.com › AshNotGrey › Node.js-Idiomatics › blob › master › sections › docker › docker-ignore.md
Node.js-Idiomatics/sections/docker/docker-ignore.md at master · AshNotGrey/Node.js-Idiomatics
On top of this include a .dockerignore file that acts as the last safety net that filters out unnecessary folders and potential secrets. Doing so also boosts the build speed - By leaving out common development folders that have no use in production ...
Author   AshNotGrey
🌐
GitHub
github.com › isa-group › project-template-nodejs › blob › master › .dockerignore
project-template-nodejs/.dockerignore at master · isa-group/project-template-nodejs
A initial template for developing Node JS project with development policy and Grunt JS for automation - project-template-nodejs/.dockerignore at master · isa-group/project-template-nodejs
Author   isa-group
🌐
Docker
docs.docker.com › guides › node.js › containerize
Containerize a Node.js application
# Optimized .dockerignore for Node.js + React Todo App # Based on actual project structure # Version control .git/ .github/ .gitignore # Dependencies (installed in container) node_modules/ # Build outputs (built in container) dist/ # Environment files .env* # Development files .vscode/ *.log coverage/ .eslintcache # OS files .DS_Store Thumbs.db # Documentation *.md docs/ # Deployment configs compose.yml Taskfile.yml nodejs-sample-kubernetes.yaml # Non-essential configs (keep build configs) *.config.js !vite.config.ts !esbuild.config.js !tailwind.config.js !postcss.config.js !tsconfig.json
🌐
GitHub
github.com › docker › getting-started › issues › 46
Add .dockerignore file for node_modules · Issue #46 · docker/getting-started
June 1, 2020 - . CMD ["node", "/app/src/index.js"] This works as intended but could lead to possibly overwriting modules installed within the image if on the host a node_modules folder already exists and is outdated. I guess a simple fix would be to add a 1-2 line .dockerignore file like proposed by Node.js.
Author   dmahnkopf
Find elsewhere
Top answer
1 of 4
12

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).

2 of 4
2

Consider docker as a entire new box, where everything will be installed and given commands to run specific tasks

In this case, try two things

  1. Create .dockerignore file and ignore all files which you think you don't want to include or let docker handles from itself.

    .git

    */node_modules

    ####### other files...

  2. And in Dockerfile just copy package.json as docker it use for deployment, so it makes sense that only package.json file will get change. So try adding COPY package*.json ./ in Dockerfile.

🌐
GitHub
github.com › contentful › the-example-app.nodejs › blob › master › .dockerignore
the-example-app.nodejs/.dockerignore at master · contentful/the-example-app.nodejs
Example app for Contentful in node.js. Contribute to contentful/the-example-app.nodejs development by creating an account on GitHub.
Author   contentful
🌐
npm
npmjs.com › package › node-dockerignore
node-dockerignore - npm
July 12, 2018 - For a complete list of differences, check out the .gitignore spec and the .dockerignore spec · Under the hood, we rewrote the entire matching logic to be much simpler · instead of complex Regex rule to replace patterns with regex, we scan through patterns · this is also modeled directly from docker's implementation · The entire API (Infate we even reuse the same index.d.ts file for TypeScript definitions) Linux + Node: 9.0 (but we use babel and it should work on older version of Node.
      » npm install node-dockerignore
    
Published   Jul 12, 2018
Version   0.0.1
🌐
GitHub
github.com › topics › dockerignore
dockerignore · GitHub Topics · GitHub
github nodejs docker dotenv express docker-compose docker-image expressjs restapi bcryptjs dockerignore ... This repository contains a simple Express.js application that serves JSON data of users and their emails. The app is dockerized using a Dockerfile and docker-compose.yml for easy deployment.
🌐
DEV Community
dev.to › nodepractices › docker-best-practices-with-node-js-4ln4
Docker best practices with Node.js - DEV Community
August 24, 2020 - FROM node:12-slim # The build logic comes here CMD ["node", "index.js"] TL;DR: Include a .dockerignore file that filters out common secret files and development artifacts. By doing so, you might prevent secrets from leaking into the image.
🌐
npm
npmjs.com › package › dockerignore
dockerignore - npm
September 7, 2015 - Command line tool for creating or updating a .dockerignore file based on .gitignore.. Latest version: 0.2.0, last published: 10 years ago. Start using dockerignore in your project by running `npm i dockerignore`. There are no other projects in the npm registry using dockerignore.
      » npm install dockerignore
    
Published   Jul 09, 2015
Version   0.2.0
Author   James Talmage
🌐
npm
npmjs.com › package › @balena › dockerignore
@balena/dockerignore - npm
May 13, 2020 - dockerignore is a file filter library compatible with Docker and the node-ignore API. Latest version: 1.0.2, last published: 6 years ago. Start using @balena/dockerignore in your project by running `npm i @balena/dockerignore`. There are 25 ...
      » npm install @balena/dockerignore
    
🌐
codestudy
codestudy.net › blog › confusion-with-node-modules-being-ignored-by-dockerignore
Why Is node_modules Not Being Ignored by .dockerignore? Fixing Common Docker + Node.js Confusion — codestudy.net
Keep .dockerignore and Dockerfile in the project root: This ensures alignment with the build context. Use **/node_modules/ in monorepos: Ignore nested dependencies. Validate with tar: Regularly check your build context with tar -czf - . | tar -tzf - to catch unignored files. Leverage layer caching: Copy package*.json before other files to cache npm install layers. Avoid docker build from parent directories: Stick to the project root for builds.
🌐
Hasura
blog.hasura.io › an-exhaustive-guide-to-writing-dockerfiles-for-node-js-web-apps-bbee6bd2f3c4
An Exhaustive Guide to Writing Dockerfiles for Node.js Web Apps
July 2, 2018 - If you’d like to jump right ahead to the code, check out the GitHub repo. Simple Dockerfile and .dockerignore · Hot Reloading with nodemon · Optimisations · Serving Static Files · Single Stage Production Build · Multi Stage Production Build · Let’s assume a simple directory structure. The application is called node-app. The top level directory has a Dockerfileand package.json The source code of your node app will be in src folder.